One-file interface to detect whether your content script have loaded.
npm install --save webext-content-script-ping
import {pingContentScript} from 'webext-content-script-ping';
From background.js
, ping a tab id:
/* globals pingContentScript */
pingContentScript(tabId).then(() => {
// the content script was loaded!
}, () => {
// the content script was NOT loaded!
});
-
In your
manifest.json
, include the file as background and as content script:{ "background": { "scripts": [ "webext-content-script-ping.js" ] }, "content_scripts": [ { "js": [ "webext-content-script-ping.js", "content.js" ] } ] }
-
In your background script only, run
pingContentScript(tabId)
as needed
// background.js
import pingContentScript from 'webext-content-script-ping';
pingContentScript(tabId);
// content.js
import 'webext-content-script-ping'; // this only responds to the ping
Returns a Promise that succeeds if the content was loaded, fails if it wasn't.
It has an internal timeout of 300ms.
Type: Tab
or number
A Tab
object or just its id
as defined here: https://developer.chrome.com/extensions/tabs#type-Tab
- webext-options-sync - Helps you manage and autosave your extension's options.
- webext-storage-cache - Map-like promised cache storage with expiration.
- webext-domain-permission-toggle - Browser-action context menu to request permission for the current tab.
- webext-dynamic-content-scripts - Automatically inject your
content_scripts
on custom domains. - webext-detect-page - Detects where the current browser extension code is being run.
Awesome WebExtensions
: A curated list of awesome resources for Web Extensions development.
MIT © Federico Brigante