Skip to content
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

Exclude URLs that already overlap with defaults #12

Closed
fregante opened this issue May 6, 2020 · 2 comments · Fixed by #28
Closed

Exclude URLs that already overlap with defaults #12

fregante opened this issue May 6, 2020 · 2 comments · Fixed by #28

Comments

@fregante
Copy link
Owner

fregante commented May 6, 2020

This shouldn't happen with https://github.com/fregante/webext-domain-permission-toggle (untested) but it can happen if the user manually adds permissions.

If manifest.json includes:

{
	"permissions": [
		"https://*.github.com/*",
	]
}

And then the extension calls browser.permissions.request('*://*/*'), neither the browser nor webext-dynamic-content-scripts will deduplicate this with existing permissions, so the scripts will be inserted twice.

@fregante
Copy link
Owner Author

fregante commented May 6, 2020

I think this can be solved by adding preexisting origins (of each content_script) in the exclude_matches prop

const registeredScript = chrome.contentScripts.register({
js: (config.js || []).map(convertPath),
css: (config.css || []).map(convertPath),
allFrames: config.all_frames,
matches: [origin],
runAt: config.run_at as browser.extensionTypes.RunAt
});

Would become:

const registeredScript = chrome.contentScripts.register({
	js: (config.js || []).map(convertPath),
	css: (config.css || []).map(convertPath),
	allFrames: config.all_frames,
	matches: [origin],
+	exclude_matches: config.matches,
	runAt: config.run_at as browser.extensionTypes.RunAt
});

@fregante
Copy link
Owner Author

Additionally this should ignore whole scripts that are already enabled on <all_urls> or *://*/*.

The implementation is different since register doesn't need to be called at all, but the concept is the same.

If every script is enabled everywhere, it could use console.warn because this module is useless in that case. A warning rather than an error would be useful for cross-browser extensions. Example: refined-github/refined-github#3766

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant