Suppose I have a JavaScript function foo()
which I want to execute in both the background and in popup.html
.
For example: it is executed every hour in the background of my Chrome extension, but can also be activated by the user from the popup menu (popup.html
) on a button click.
I currently have a global.js
script which defines foo()
and when I include calls to foo()
in my popup.js
document, they execute without issue. (If I include both scripts in popup.html
)
However, when I try to access foo()
inside background.js
, the calls do not execute (even if global.js
is included in the background manifest.json extension file:
background: {
persistent: true,
scripts: [background.js, global.js]
},
Is there a convenient way to share functions between background.js
and popup.js
(without copying the entire function into each)?