-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use more smaller files and imports #11
Comments
Here are some notes about importing in For context, Stardown uses Firefox manifest v2 because of this bug: 1851083 - Manifest V3 extensions with activeTab/tabs permission require user interaction not previously required, showing blue dot on desktop and no indicator on Android. I created export async function getSetting(name, default_) {
...
} In Loading the extension gives the error I made "background": {
"scripts": [
"background.js",
"common.js"
],
"type": "module"
}, This changes the error message to Wrapping the let getSetting;
import('./common.js').then((exports) => {
getSetting = exports['getSetting'];
getSetting('doubleClickInterval', 500).then(value => doubleClickInterval = value);
}); Neither does replacing <!DOCTYPE html>
<html>
<body>
<script type="module" src='./background.js'></script>
</body>
</html> Neither does using both I put When I comment out Uncommenting the Using this in "background": {
"page": "background.html"
}, and this <!DOCTYPE html>
<html>
<body>
<script type="module" src='./common.js'></script>
<script type="module" src='./background.js'></script>
</body>
</html> with the Removing both instances of Maybe Firefox manifest v2 doesn't allow the use of One of the sources I looked at for ideas: [WebExtension] Import a module in a script |
About the problem with Chrome giving us the error message Chrome version 125.0.6422.142 ... [6764:6656:0607/204034.346:VERBOSE1:script_context.cc(149)] Created context: ... [8796:6160:0607/204040.099:VERBOSE1:script_context.cc(149)] Created context: ... [8476:22148:0607/204025.928:WARNING:load_error_reporter.cc(72)] Extension error: Failed to load extension from: C:\Users\chris\Documents\programming\Stardown\chrome. Manifest file is missing or unreadable ... [6764:6656:0607/204434.453:VERBOSE1:script_context.cc(162)] Destroyed context for extension |
Continuing with trying to fix Chrome's I repeated all of these steps again with the Not even the most simple cases of importing and exporting are working for Chrome content scripts. We may need to use a bundler for Chrome as well. |
From javascript - How to import ES6 modules in content script for Chrome Extension - Stack Overflow, many people don't expect to be able to use or need import and export statements in content scripts. Apparently, content scripts are all loaded together in the order listed in the manifest as if they're one big file. However, some of Stardown's code used in the content is also used in the background, so it's not an easy choice to just remove the |
Here is Stardown's current file structure: flowchart TD
menu.js --> chromiumConfig.js
menu.js --> firefoxConfig.js
common.js --> md.js
chromiumConfig.js --> content.js
firefoxConfig.js --> content.js
common.js --> content.js
md.js --> content.js
createTextFragmentArg.js --> content.js
chromiumConfig.js --> background.js
firefoxConfig.js --> background.js
common.js --> background.js
md.js --> background.js
common.js --> options.js
I don't see a way to change this so that it has no files that both import and export, unless we go back to using something like @chizuo Changing Stardown to not use both Using the let menu;
(async () => {
menu = await import(browser.runtime.getURL('./menu.js'));
})(); However, our use case is not simple enough for the It looks like we might have no choice but to use a bundler for Chrome. |
The background and content scripts should be split into multiple files to improve organization and to reuse some duplicate code.
In particular, some of the functions are defined multiple times for each browser extension, such as
getSetting
which is defined 5 times total.The text was updated successfully, but these errors were encountered: