Well for others who may look here for that error message in a similar context, I got the same error when neglecting to make the window
object accessible at runtime rather than at the time that the injected function is dynamically being readied for injection into a particular tab by the v3 background script.
In order to get dynamically injected from a v3 background script, the tab specific object (in this case window
) needs to be included inside the function being passed, as in the following anonymous function case:
chrome.scripting.executeScript({
target: { tabId: currentTab.id },
func: () => window.history.back()
});
if window.history.back
is provided as the value for func
then obviously it will not be known or available to the background script and the same error message will ensue.
This is already described indeed in the docs.
window
. Why do you need window.width in the background script? – Hypnotherapy