New issue
Advanced search Search tips

Issue 677692 link

Starred by 2 users

Issue metadata

Status: WontFix
Owner: ----
Closed: Dec 2016
Cc:
EstimatedDays: ----
NextAction: ----
OS: Mac
Pri: 2
Type: Bug-Regression



Sign in to add a comment

chrome.runtime.sendMessage inconsistent behaviour among Chrome versions

Reported by awcal...@gmail.com, Dec 31 2016

Issue description

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:50.0) Gecko/20100101 Firefox/50.0

Steps to reproduce the problem:
1. add message listener - chrome.runtime.onMessage.addListener
2. call chrome.runtime.sendMessage in the same page
3. message listener is not triggered

What is the expected behavior?
Message listener should be triggered.

What went wrong?
I have tested this on Chrome 55,56 and it worked well on those versions. I attached test addon which opens test html page, if listener is triggered the page will open an alert window.

Did this work before? Yes Chrome 56

Does this work in other browsers? N/A

Chrome version: 57.0.2968.0 (Official Build) canary (64-bit)  Channel: n/a
OS Version: OS X 10.10
Flash Version: Shockwave Flash 18.0 r0
 
send-message.zip
996 bytes Download

Comment 1 by woxxom@gmail.com, Dec 31 2016

Bisect:
436652 (good) - 436659 (bad), 57.0.2944.0
https://chromium.googlesource.com/chromium/src/+log/3d074282..48f434bf?pretty=fuller
Suspecting r436655 "[Extensions] Extension Port Ids and Initialization 2.0" as the only extensions-related change.

Comment 2 by rob@robwu.nl, Dec 31 2016

Cc: rob@robwu.nl
Status: WontFix (was: Unconfirmed)
This is the expected behavior.

chrome.runtime.sendMessage should not trigger chrome.runtime.onMessage in the same window. This used to not be consistently followed (for a detailed comparison, see https://bugzilla.mozilla.org/show_bug.cgi?id=1286124#c10), but that was fixed with  bug 597698 .

If you want to trigger events in the same page, use DOM events (addEventListener + CustomEvent + dispatchEvent) or a custom event emitter library.

Comment 3 by awcal...@gmail.com, Jan 1 2017

Thanks for clarification.

In my extension I want messages to be delivered in every frame of extension, including the sender's frame, can I rely on Chrome version to predict sendMessage behaviour? For example:

- Chrome version < 57, use only sendMessage to deliver messages to all frames
- Chrome version >= 57, use sendMessage to deliver a message to different frames and some logic to deliver the message to the current frame

Comment 4 by rob@robwu.nl, Jan 1 2017

#3 Even before version 57 you cannot rely on the message being triggered in the sender's frame. For even more details on when onMessage is not triggered, see https://bugzilla.mozilla.org/show_bug.cgi?id=1286124#c35

If there are always two or more extension frames (e.g. an extension page with one iframe), then what you are describing would work. In coding the logic, I suggest to assume that the browser behaves as documented, unless they are using Chrome < 57.

Sign in to add a comment