2

I have a chrome extension that have a popup.js file. My main problem is that inside the popup.js file there are 6 functions, and I want to separate these function in multiples JS files and import them in popup.js (mostly for maintenance questions)

Require does not work in my case, does anybody know how to do that ?

manifest.json

{
    "name": "xxx",
    "version": "1.2.7",
    "description": "xxx",
    "manifest_version": 2,
    "icons": { "128": "0.png" },

    "background": {
        "scripts": ["background.js"],
        "persistent": false
    },
    "permissions": [
        "activeTab",
        "storage",
        "contextMenus",
        "background",
        "cookies",
        "notifications",
        "https://www.linkedin.com/*",
        "https://linkedin.com/*"
    ],
    "browser_action": {
        "default_popup": "popup.html"
    }
}

popup.html

<!DOCTYPE html>
<html lang="en">
    <head>
    <meta charset="UTF-8" />
        <link rel="stylesheet" href="style.css" />
    </head>
    <body>

      <h1 class="ui center aligned header ">
         <span class="highlighted-orange">HubLinked
         </span>
      </h1>


    </body>
    <script type="text/javascript" src="popup.js"></script>
</html>

Kara
  • 67
  • 2
  • 5
  • Just add them after your include of popup.js. or do you mean dynamically through js code? – Patrick Evans Apr 27 '19 at 15:37
  • For example, I have a function test in my popup.js. I want to move this function into another file : test.js And make this function available in popup.js – Kara Apr 27 '19 at 15:39
  • Use as many ` – Iván Nokonoko Apr 27 '19 at 15:40
  • `require` doesn't work in browsers at all, unless you provide a polyfill of this function or build your code with webpack and so on. You can use ES-modules or just add more script tags in html so that all scripts will be running in the common global namespace. – wOxxOm Apr 27 '19 at 15:40
  • Thanks Ivan, that's worked !!! Thanks all for your help – Kara Apr 27 '19 at 15:44

0 Answers0