0

While the following does set the page title.

chrome.tabs.executeScript(1857434626, { code: `document.title = "newtitle."` });

The following doesn't set document.foobar on the page.

chrome.tabs.executeScript(1857434626, { code: `document.foobar = "foobar."` });

On the page open devtools, console tab, document.foobar, it shows undefined. While document.title shows newtitle..

I need to pass a data/parameter/variable to a page from Chrome background script, so it later will be accessible from the page or from Tampermonkey for example.

The title way, I have no idea why but somehow works, is not a very good solution since 1. title length is limited 2. title may change by the site/app 3. I prefer keep the title as is.

You may suggest modifying the html on the page, just adding a script tag with a stringified json. But no, I prefer keep the html as is, and I believe that there should be a better/smarter way.

Thanks.

0 Answers0