-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
How to integrate the API of SingleFile into an extension
Gildas edited this page Sep 8, 2019
·
55 revisions
- Copy from SingleFile the
lib
folder, theextension/index.js
file and theextension/lib
folder. - Create a
manifest.json
file containing the content below.
{
"name": "<Extension name>",
"author": "<Author>",
"version": "0.0.1",
"description": "<Description>",
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"run_at": "document_start",
"js": [
"lib/index.js",
"extension/index.js",
"extension/lib/browser-polyfill/chrome-browser-polyfill.js",
"lib/single-file/single-file-helper.js",
"lib/hooks/content/content-hooks-frames.js",
"lib/frame-tree/content/content-frame-tree.js"
],
"all_frames": true,
"match_about_blank": true
},
{
"matches": [
"<all_urls>"
],
"run_at": "document_start",
"js": [
"lib/index.js",
"lib/hooks/content/content-hooks.js"
]
}
],
"background": {
"scripts": [
"lib/index.js",
"extension/index.js",
"extension/lib/browser-polyfill/chrome-browser-polyfill.js",
"extension/lib/core/bg/scripts.js",
"extension/lib/fetch/bg/fetch.js",
"extension/lib/frame-tree/bg/frame-tree.js",
"extension/lib/lazy/bg/lazy-timeout.js"
],
"persistent": false
},
"web_accessible_resources": [
"lib/hooks/content/content-hooks-web.js",
"lib/hooks/content/content-hooks-frames-web.js"
],
"permissions": [
"activeTab",
"<all_urls>"
],
"incognito": "spanning",
"manifest_version": 2
}
- Inject SingleFile scripts in the tab to save by executing the code below in the background script.
await singlefile.extension.injectScript(tabId, options);
-
Arguments
-
tabId
is a Tab id -
options
is an object containing the options to pass to SingleFile. The default values can be found in theextension/core/bg/config.js
file.
-
-
Capture the page by executing the code below in the content script of the tab where the Singlefile has been injected.
const pageData = await singlefile.extension.getPageData(options);
- Arguments
-
tabId
is a Tab id -
options
is an object containing the options to pass to SingleFile.
-
- Return
- An object having a property
content
which contains the content of the page.
- An object having a property