0

I'm studying chrome extension MV3 recently. I've try to run chrome.runtime.sendMessage() example code. https://developer.chrome.com/docs/extensions/reference/runtime/

The example was writing chrome.runtime.sendMessage() to "contents.js" and chrome.runtime.onMessage.addListener() to background.js .

/// popup.js

chrome.runtime.sendMessage('get-user-data', (response) => {
    console.log('received user data', response);
});

// background.js

chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
    if (message === 'get-user-data') {
        console.log(message);
    }
});

But I written sendMessage to popup.js . I show my extension popup pane then chrome has crashed.

So I've try to watch chrome debug log.

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --enable-logging --v=1

It had appear one warning .

[0504/063939.130152:WARNING:process_memory_mac.cc(93)] mach_vm_read(0x7ffee5ab0000, 0x2000): (os/kern) invalid address (1)

"invalid address" ? This is chrome bug ? or I can't write runtime.sendMessage() on popup.js ?

  • Since this code works for everyone, you must have encountered a rare bug in Chrome so you can report it on https://crbug.com. P.S. To send a message to a content script you need to use chrome.tabs.sendMessage with a tab id, not chrome.runtime.sendMessage. See also [How to open the correct devtools console to see output from an extension script?](https://stackoverflow.com/a/38920982). – wOxxOm May 04 '21 at 03:56
  • @wOxxOm Thank you for the appropriate comment. I'll do that. – positrium May 04 '21 at 13:54

0 Answers0