-
Notifications
You must be signed in to change notification settings - Fork 121
External Message API
Webscrapbook allow other extensions to trigger
capturing with send message.
Two type of messages are allowed:
{cmd: "invokeCapture"}
and {cmd: "invokeCaptureEx"}
(defined in onMessageExternal event and scrapbook.invokeCapture).
Both of them require arguments in args
property.
To send message to webscrapbook,
an extension should call browser.runtime.sendMessage
with webscrapbook's extension id as the first argument.
Extension id can be found in about:debugging#/runtime/this-firefox
(firefox) or chrome://extensions
in developer mode (chromium).
Firefox allow author to specify extension id in its manifest,
so webscrapbook's id should always be [email protected]
(defined in webscrapbook's manifest).
Chromium will always generate a random id while installation.
Extensions can also look up other extensions' id
from WebExtensions management.getAll api.
This requires a management permission in manifest.
Note webscrapbook's ExtensionInfo is localized,
so you may need to test on the non-localized properties
like homepageUrl
.
const extensions = await browser.management.getAll();
const webscrapbook = extensions.find(info =>
/danny0838.webscrapbook/.test(info.homepageUrl)
);
const id = webscrapbook.id;
A message with cmd: 'invokeCapture'
property should specify
the tabs to captured with its tab id, and webscrapbook will
capture the tabs in default options.
The args
should be a array of objects which hold a integer tabId
property.
While capturing, webscrapbook will open a capture window, and capture every tab specified in args in sequence in that capture window.
This example will capture the current focused tab.
Note the browser.tabs
api will not work in content scripts.
// in firefox
let extensionId = "[email protected]";
const tabs = await browser.tabs.query({active: true, currentWindow: true});
const tabId = tabs[0].id;
await browser.runtime.sendMessage(extensionId, {
cmd: "invokeCapture",
args: [{tabId: tabId}]
});
To be continue...