NEW263819
tabs.sendMessage not getting any response back if script wasn't injected
https://bugs.webkit.org/show_bug.cgi?id=263819
Summary tabs.sendMessage not getting any response back if script wasn't injected
Guilherme Rizzo
Reported 2023-10-27 19:16:57 PDT
If you try to run: browser.tabs.sendMessage(tab.id, { text: "are_you_there_content_script?" }, function (msg) { msg = msg || {} if (msg.status !== 'yes') { chrome.scripting.executeScript({ ... }) } } ) In Chrome and Firefox, the function gets called no matter the response. In Safari, the function never runs because no script has been injected into the page so far. Always getting a response back, even if empty, undefined, or null, would make checking if scripts were injected much easier. This is useful to run executeScript only when asked for and only once, without managing a state with a variable by pushing and removing tabIds where it has run. Otherwise, people will add content scripts that always run - much heavier than executing scripts only when requested.
Attachments
Radar WebKit Bug Importer
Comment 1 2023-10-27 19:17:05 PDT
Guilherme Rizzo
Comment 2 2025-03-28 18:37:52 PDT
Any updates? This is the main thing stopping me from upgrading my extension to the new model.
Karl Dubost
Comment 3 2025-03-30 19:37:40 PDT
@Guilherme which version of WebKit/Safari on which device are you using?
Note You need to log in before you can comment on or make changes to this bug.