I am developing an extension that interacts with a website of ours. The interaction is created by sending messages along and handling those.
Sometimes I want to open our website in incognito mode and there, the extension is not working. It looks to me that the listeners
on chrome.runtime.onMessage
are not triggered.
in my contentScript.js
I have something like
window.addEventListener(
'message',
(event, r) => {
//check for sender and type otherwise return;
chrome.runtime.sendMessage(data);
}
);
The extension creates a devtools_page
, which loads a .html
.
On that page I have
chrome.runtime.onMessage.addListener(messageHandler)
the messageHandler
is never triggered. I can even check if the listener is there with chrome.runtime.onMessage.hasListener(messageHandler)
, which returns true
.
Even when I put the listener in the background.js
(set in the manifest.json
), this listener is never triggered.
I tried to put "incognito": "split"
into the manifest.json
but then the browser crashed completely when I open the page in incognito tab. For permissions, I have ["cookies", "tabs"]
.
Update: I enabled the extension in incognito mode on the extensions settings page
Update: As I said, when setting "incognito": "split"
, the browser crashes. I narrowed it down to my contentScript.js
which is loaded by the manifest "content_scripts"
. I removed everything. Loading the page, the browser does not crash. But as soon as I run window.addEventListener
, the browser crashes when I open the site on an incognito tab
Update: in the windowAddEventListener
I do a chrome.runtime.sendMessage(data)
. I do this to make the website able to send necessary information to the extension to show the data. When removing chrome.runtime.sendMassage
, the browser does not crash in incognito mode with "incognito":"split"