Skip to content

Commit

Permalink
Load tab preview frame script as non-module code
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Dec 24, 2024
1 parent fbad55b commit 7b57730
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion webextensions/sidebar/tab-preview-tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ function generateOneTimeCustomElementName() {
return prefix + '-' + Date.now() + '-' + Math.round(Math.random() * 65000);
}

let mDirectLoadScript;

async function prepareFrame(tabId) {
const tab = Tab.get(tabId);
if (!tab)
Expand All @@ -130,9 +132,14 @@ async function prepareFrame(tabId) {
// if the tab is TST's internal page, because Firefox closes such tabs
// when the addon is reloaded. Instead we load tab preview frame script
// to the internal page directly.
if (!mDirectLoadScript) {
const response = await fetch('/resources/module/tab-preview-frame.js');
const moduleScript = await response.text();
mDirectLoadScript = moduleScript.replace(/^export /gm, '');
}
await browser.tabs.executeScript(tabId, {
runAt: 'document_start',
file: '/resources/module/tab-preview-frame.js',
code: mDirectLoadScript,
});
return;
}
Expand Down

0 comments on commit 7b57730

Please sign in to comment.