Skip to content Skip to sidebar Skip to footer

How To Load Js From A Chrome Extension Popup

background I simply want to create a chrome extension where I click on the extension icon, it loads a popup that loads a javascript file. I was able to do an html only popup simpl

Solution 1:

Many ways:

  1. Add a script for example popup.js in popup.html and call chrome.runtime.getBackgroundPage(function callback) to interact with event page.

    popup.html

    ...
    <scriptsrc="popup.js"></script>
    ...
    

    popup.js

    chrome.runtime.getBackgroundPage(backgroundPage => backgroundPage.testMethod());
    

    eventsPage.js

    consttestMethod = () => console.log('test');
    
  2. Use Message Passing(there are many examples in this link) to communicate with event page.

  3. Since you want to transfer data between popup page and event page, there are many other workarounds, for example, we could use global storage such as chrome.storage to save/load/react to changes.

Post a Comment for "How To Load Js From A Chrome Extension Popup"