Skip to content

chore: comments about chrome in executeScript #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2024
Merged
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
21 changes: 6 additions & 15 deletions static/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ function courier(tabId, changed) {
// a limbo world where both `chrome` and `window` are defined
// with many unexpected and out of the ordinary behaviors, do
// minimal work here and delegate to `courier.js` in the page.
// only a subset of APIs are available in this `chrome` limbo
// - chrome.csi->f()
// - chrome.dom.{openOrClosedShadowRoot->f()}
// - chrome.extension.{ViewType, inIncognitoContext}
// - chrome.i18n
// - chrome.runtime
func: () => {
const source = chrome.runtime.getURL('/courier.js');
if (document.querySelector(`script[src="${source}"]`)) return;
Expand All @@ -72,24 +78,9 @@ function courier(tabId, changed) {
script.setAttribute('src', source);
document.head.appendChild(script);

// // TODO: reenable profiler
// if (message.type === 'bridge::ext/profiler' && message.payload) {
// // start profiler
// }

chrome.runtime.onMessage.addListener((message, sender) => {
if (sender.id !== chrome.runtime.id) return; // unexpected sender
window.postMessage(message); // relay to content script (courier.js)

// switch (message.type) {
// case 'startProfiler':
// window.sessionStorage.SvelteDevToolsProfilerEnabled = 'true';
// break;
// case 'stopProfiler':
// case 'bridge::ext/clear':
// delete window.sessionStorage.SvelteDevToolsProfilerEnabled;
// break;
// }
});

window.addEventListener('message', ({ source, data }) => {
Expand Down