New issue
Advanced search Search tips

Issue 759474 link

Starred by 5 users

Issue metadata

Status: Assigned
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Mac
Pri: 2
Type: Bug



Sign in to add a comment

sender.frameId is empty for messages sent from background child frame

Reported by siria...@gmail.com, Aug 28 2017

Issue description

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36

Steps to reproduce the problem:
Append iframe in background page and send message from content script of this frame. 

Easier way to reproduce:

1. manifest.json:
{
  "name": "Test",
  "manifest_version": 2,
  "version": "0.1",
  "content_scripts": [
    {
      "js": [
        "content.js"
      ],
      "matches": ["<all_urls>"],
      "run_at": "document_start",
      "all_frames": true
    }
  ],
  "background": {
    "scripts": ["background.js"]
  }
}

2. content.js
chrome.runtime.sendMessage('');

3. background.js

chrome.runtime.onMessage.addListener((m,sender) => console.log(sender));

function test() {
    let frame = document.createElement('frame');
    frame.src = 'https://example.org';
    document.body.appendChild(frame);
}

if (document.body) {
    test()
} else {
    document.addEventListener("DOMContentLoaded", test);
}

What is the expected behavior?
At least sender.frameId must not be empty. Because child frame 100% HAS unique frameId (you could check it using for example chrome.webRequest API)

What went wrong?
sender object contains only "id" and "url" properties. But must also contain at least "frameId" property

Did this work before? N/A 

Does this work in other browsers? N/A

Chrome version: 60.0.3112.113  Channel: stable
OS Version: OS X 10.12.5
Flash Version:
 

Comment 1 by siria...@gmail.com, Aug 28 2017

Likely duplicates https://bugs.chromium.org/p/chromium/issues/detail?id=582744 but I submitted new, since 582744 was opened 1.5 years ago and not resolved yet

Comment 2 by siria...@gmail.com, Aug 28 2017

Same issue affects browser_action pages too (and probably all other pages with tabId === -1)
 Issue 759473  has been merged into this issue.
Labels: Needs-Triage-M60
Cc: pnangunoori@chromium.org
Labels: Needs-Feedback
@sirianru-- Thanks for reporting the issue. Could you also please provide the sample HTML file or extension to reproduce the issue. That would help us to test and triage the issue further.

Thanks in advance.

Comment 6 by shrike@chromium.org, Sep 16 2017

Components: Blink
[mac bug triage]
Cc: rdevlin....@chromium.org
Components: -Blink Platform>Extensions
rdevlin.cronin@	perhaps you can help triage this (and issue 582744) since it hasn't moved in a while. 

Cc: catmulli...@chromium.org rob@robwu.nl
Status: Untriaged (was: Unconfirmed)
Hmm, interesting.  Technically, this *is* documented behavior:
https://developer.chrome.com/extensions/runtime#type-MessageSender

frameId: The frame that opened the connection. 0 for top-level frames, positive for child frames. This will only be set when tab is set.
tab: The tabs.Tab which opened the connection, if any. This property will only be present when the connection was opened from a tab (including content scripts), and only if the receiver is an extension, not an app.

So |frameId| only exists if |tab| exists, and |tab| only exists if it was a tab that sent the message, and in this case, it's not a tab sending the message (since the background page isn't a tab).

That said, I don't see any reason that frameId has to be linked to |tab| existing - we should have the frame id in any case.

Rob, it looks like you added this property back in revision 248d6a8456fdf67fa11be00e35105642f1871a9b; was there a reason to only include it when tab existed?

Comment 9 by siria...@gmail.com, Sep 20 2017

I've created extension example on github. 
https://github.com/sirian/chrome-issue-759474

In background page you will see log like

> webRequest sub_frame tabId: -1, frameId: 666
> webRequest other tabId: -1, frameId: 666
> onMessage {id: "glcgkmjooeahdmmadodabpkgdlndjebn", url: "https://example.org/"}

so frameId is exist and exposed at webRequest API. But not exposed at messaging API

Comment 10 by rob@robwu.nl, Sep 20 2017

> Rob, it looks like you added this property back in revision 248d6a8456fdf67fa11be00e35105642f1871a9b; was there a reason to only include it when tab existed?

At the time, the "frameId" was based on the routing ID, which was only unique per rendering process, and hence required a tab ID to uniquely identify a frame. When out-of-process frames started to become a thing, we switched to FrameTreeNode IDs, which is unique across all processes ( bug 432875 ).

I did intentionally did not document that frame IDs can uniquely identify frames, to allow the implementation to revert to non-unique IDs. However, it seems that the "frame ID" will continue to be globally unique since there is no reason to have another implementation. Moreover, the "frame IDs" in Firefox's independently developed WebExtensions API is also (statistically) unique across processes. Hence it is likely that the IDs will always be unique.

I think that it's OK to include frameId in a message from the background page.

When we do that, we should also consider allowing certain tab APIs to be used with tab ID "-1" and frameId, e.g.
chrome.tabs.connect
chrome.tabs.sendMessage
chrome.tabs.executeScript
chrome.tabs.insertCSS

Before supporting that, we need to check whether we really want to allow "-1" to be used for valid destinations, or whether we want to introduce a new tab ID, e.g. "-3" for "contexts that are not part of a tab, but that can contain frames."


> so frameId is exist and exposed at webRequest API. But not exposed at messaging API

in webRequest, the ExtensionApiFrameIdMap is used, which does not "ignore" frame tree node IDs for missing tabIDs:
https://chromium.googlesource.com/chromium/src/+/ee78727e1b88b5cd3310fc09f5be55c853ac8e37/extensions/browser/extension_api_frame_id_map.cc#167
https://chromium.googlesource.com/chromium/src/+/ee78727e1b88b5cd3310fc09f5be55c853ac8e37/extensions/browser/extension_api_frame_id_map.cc#358
The frameId provider does not take the (non-existence) of tabId into account either:
https://chromium.googlesource.com/chromium/src/+/ee78727e1b88b5cd3310fc09f5be55c853ac8e37/extensions/browser/extension_api_frame_id_map.cc#101

Whereas in extension messaging, the frameId is only set when the tabId is set:
https://chromium.googlesource.com/chromium/src/+/21f6df2a9bbb8c7bc60186c2ae1792b8361e1c5d/extensions/browser/api/messaging/message_service.cc#252
Cc: -catmulli...@chromium.org
Owner: rdevlin....@chromium.org
Status: Assigned (was: Untriaged)
Mac triage: assigning to rdevlin.cronin@ for further triage per #10.
Owner: dbertoni@chromium.org
I think this would be a good one for dbertoni@ to tackle.  I think it does make sense to include frameId on all messages.

As a first step, I'd say we should just have those events include the frameId.  I like Rob's idea of potentially using frameId more broadly (and exercising its uniqueness), but I think that probably warrants a separate discussion/bug.
Any news? Or this had sunk into oblivion like https://bugs.chromium.org/p/chromium/issues/detail?id=582744 ?)

Sign in to add a comment