0.0.0 • Published 3 years ago

webext-inject-content-scripts v0.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

webext-inject-content-scripts

WebExtensions: Polyfill for browser.contentScripts.register() for Chrome and Safari.

Install

You can download the standalone bundle and include it in your manifest.json.

npm install webext-inject-content-scripts
import 'webext-inject-content-scripts';

Usage

Include the script via manifest.json, then refer to the original contentScripts.register() documentation.

const registeredScript = await chrome.contentScripts.register({
	js: [{
		file: 'myfile.js'
	}],
	matches: [
		'https://google.com/*'
	]
});

Additionally, if you're using webextension-polyfill, you can also use it with the original browser.* name: browser.contentsScripts.register()

const registeredScript = await browser.contentScripts.register({
	js: [{
		file: 'myfile.js'
	}],
	matches: [
		'https://google.com/*'
	]
});

Permissions

Generally you don't need any permissions other than the host permission you want to register a script on.

However to use allFrames: true you should the webNavigation permission. Without it, allFrames: true will work "with bugs." It won't work:

  • when the iframe is not on the same domain as the top frame
  • when the iframe reloads or navigates to another page
  • when the iframe is not ready when runAt is configured to run (runAt: 'start' is unlikely to work)

Related

License

MIT © Federico Brigante