'Chrome addons (plugins) javascript files seem isolated

I have created an unpacked plugin for Chrome (that also works in Firefox), that has a single script.js file. And it works.

However, trying to call a function included in the addon's script.js file from the console results in:

Uncaught ReferenceError: _islet_convert is not defined
at <anonymous>:1:1

(anonymous) @ VM259:1

Which by the way I tested just to verify with not_a_function() in the console, and the error was the same.

Can someone tell me how Chrome and probably Firefox handles or isolates the JavaScript in the content_scripts files? And if there is any way to reference a function/method in the file.



Solution 1:[1]

From the documentation in Chrome:

https://developer.chrome.com/docs/extensions/mv2/content_scripts/

Content scripts live in an isolated world, allowing a content script to makes changes to its JavaScript environment without conflicting with the page or additional content scripts.

...

Isolated worlds do not allow for content scripts, the extension, and the web page to access any variables or functions created by the others. This also gives content scripts the ability to enable functionality that should not be accessible to the web page.

Essentially, it appears any communication needs to happen through the DOM including adding event listeners.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Oliver Williams