0

I have a chrome extension that uses native messaging to send messages between the extension and a local application. Some users have reported errors on certain pages that they receive errors when the extension is enabled.

Specifically some of those pages show that a message from my extension is being interpreted by the page.

Multiple google searches seem to indicate the problem is unique. The extension uses a port object in the background page to send the message as follows:

var message = {
                    pageId : tabId,
                    type   : "request",
                    fnName : request.name,
                    data   : request.data
                };
if (myExtension_port) {
    myExtension_port.postMessage(message);
}

Is there a known solution that I'm missing?

I've already reviewed the chrome extension developer documentation a few times.

mgbowe1
  • 51
  • 8
  • Extension messaging via chrome.runtime cannot be intercepted unless there's a bug in Chrome or the page has used an elaborate Spectre/Meltdown attack or you're using chrome.runtime in [page context](/a/9517879) and the page has spoofed it. Anyway, the posted fragment of code is not sufficient to diagnose the problem. What exactly do you mean by "a message from my extension is being interpreted by the page"? If you use a content script then show the relevant code. If you run code in [page context](/a/9517879) show that code as well. – wOxxOm May 23 '20 at 04:54
  • Thanks, it looks like we had a section of the code running in the page context and using postMessage to communicate. The pages that were breaking were listening for messages, but not failing gracefully when they saw an unexpected one. – mgbowe1 Jun 15 '20 at 19:30
  • Yep, some sites are like that. Use CustomEvent instead, [example](https://stackoverflow.com/a/19312198). – wOxxOm Jun 15 '20 at 19:50

0 Answers0