Issue metadata
Sign in to add a comment
|
chrome.runtime.sendMessage inconsistent behaviour among Chrome versions
Reported by
awcal...@gmail.com,
Dec 31 2016
|
||||||||||||||||||||
Issue descriptionUserAgent: 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
,
Dec 31 2016
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.
,
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
,
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 |
|||||||||||||||||||||
Comment 1 by woxxom@gmail.com
, Dec 31 2016