Bug 263819 - tabs.sendMessage not getting any response back if script wasn't injected
Summary: tabs.sendMessage not getting any response back if script wasn't injected
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Extensions (show other bugs)
Version: Safari 16
Hardware: Mac (Apple Silicon) macOS 13
: P2 Normal
Assignee: Nobody
URL:
Keywords: BrowserCompat, InRadar
Depends on:
Blocks:
 
Reported: 2023-10-27 19:16 PDT by Guilherme Rizzo
Modified: 2024-01-02 13:09 PST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Guilherme Rizzo 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.
Comment 1 Radar WebKit Bug Importer 2023-10-27 19:17:05 PDT
<rdar://problem/117614209>