Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ async function onBeforeRequest(
const tab = await browser.tabs.get(request.tabId);
const sourceUrl = tab.url ? new URL(tab.url) : undefined;

const tabContainerName = (await browser.contextualIdentities.get(tab.cookieStoreId)).name;

const interpreter = new Sval({
ecmaVer: "latest",
sourceType: "script",
sandBox: true,
});
interpreter.import({ url: new URL(request.url), sourceUrl });
interpreter.import({ url: new URL(request.url), sourceUrl, containerName: tabContainerName });
interpreter.run(program);

const info = toContainerInfo(interpreter.exports.end);
Expand Down
1 change: 1 addition & 0 deletions ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ <h1>Container Script</h1>
<ul style="color: #34495e; line-height: 1.8; margin-bottom: 15px;">
<li><code>url</code> &mdash; the <a href="https://developer.mozilla.org/en-US/docs/Web/API/URL">URL</a> being navigated to.</li>
<li><code>sourceUrl</code> &mdash; the URL of the page that initiated the navigation (may be <code>undefined</code> for new tabs).</li>
<li><code>containerName</code> &mdash; the name of the current container of the tab (before the change).</li>
</ul>
<p>
The code is executed using <a href="https://github.com/Siubaak/sval">Sval</a> due to <a href="https://www.w3.org/TR/CSP/">CSP</a> restrictions.
Expand Down
4 changes: 4 additions & 0 deletions ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ async function main() {
" * The URL of the page that initiated the navigation (may be undefined for new tabs)",
" */",
"declare const sourceUrl: URL | undefined",
"/**",
" * The name of the current container of the tab",
" */",
"declare const containerName: string | undefined",
].join("\n");
const libUri = "ts:filename/ContainerScript.d.ts";
monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, libUri);
Expand Down