webext-content-script-ping
One-file interface to detect whether your content script have loaded.
Install
npm install --save webext-content-script-ping
;
Usage
From background.js
, ping a tab id:
/* globals pingContentScript */;
Plain files
-
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
With a bundler
// background.js;;
// content.js; // this only responds to the ping
API
pingContentScript(tab)
Returns a Promise that succeeds if the content was loaded, fails if it wasn't.
It has an internal timeout of 300ms.
tab
Type: Tab
or number
A Tab
object or just its id
as defined here: https://developer.chrome.com/extensions/tabs#type-Tab
Related
webext-options-sync
: Helps you manage and autosave your extension's options.webext-inject-on-install
: Automatically add content scripts to existing tabs when your extension is installed.Awesome WebExtensions
: A curated list of awesome resources for Web Extensions development.
License
MIT © Federico Brigante — Twitter