2.0.1 • Published 6 years ago

webext-content-script-ping v2.0.1

Weekly downloads
11
License
MIT
Repository
github
Last release
6 years ago

webext-content-script-ping Travis build status npm version

One-file interface to detect whether your content script have loaded.

Install

npm install --save webext-content-script-ping
import {pingContentScript} from 'webext-content-script-ping';

Usage

From background.js, ping a tab id:

/* globals pingContentScript */
pingContentScript(tabId).then(() => {
	// the content script was loaded!
}, () => {
	// the content script was NOT loaded!
});

Plain files

  1. 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"
    			]
    		}
    	]
    }
  2. In your background script only, run pingContentScript(tabId) as needed

With a bundler

// background.js
import pingContentScript from 'webext-content-script-ping';
pingContentScript(tabId);
// content.js
import 'webext-content-script-ping'; // 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

License

MIT © Federico Brigante — Twitter

2.0.1

6 years ago

3.0.0

6 years ago

2.0.0

6 years ago

2.0.0-2

6 years ago

2.0.0-1

6 years ago

2.0.0-0

6 years ago

1.1.1-0

6 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago