New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 840917 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner:
Closed: Nov 5
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: iOS
Pri: 1
Type: Compat



Sign in to add a comment

Calling sendMessage from cross origin iframe throws a SecurityError.

Project Member Reported by mfo...@chromium.org, May 8 2018

Issue description

Chrome Version: 66.0.3359.122
OS: iOS 11.3.1

What steps will reproduce the problem?
(1) Load the following pen: https://codepen.io/nironiro78/pen/ZoLJjQ/

Ignore the first bit in the pen about loading Google Cast.  That code is not invoked AFAICT.

What is the expected result?
The pen writes "[object HTMLDivElement]" forever

What happens instead?
The pen writes "[object HTMLDivElement]" 5-7 times then triggers the exception handler with an alert:

isNode: false, error: TypeError: Argument 1 ('node') to Node.appendChild must be an instance of Node

Note that this pen works as expected in Safari.
 
Cc: fergal@chromium.org
Components: -Blink>DOM Internals>Cast
Labels: -Pri-3 OS-Linux Pri-2
Summary: when cast API becomes available DOM objects start to misbehave (was: document.getElementById returns a non-Node value when called repeatedly)
The _exception_ doesn't repro for me on Linux but something does happen. As far as I can tell, the gcast available API callback is causing something to change. On linux, I see "GoogleCast Loaded" after 5-7 iterations at which point console logging changes in a weird way. Presumably you would also see it on Mac if the exception didn't occur.

To repro this open

https://codepen.io/anon/pen/rvpXdm

and then open the devtools console. What you see is that the console logging output is different when castAvailable becomes true. See the attached screenshot. This means that something has changed. On Mac the change triggers an exception, on Linux it interferes with console.log.

Passing this to the cast folks and bumping the priority since it seems like some fundamentals break when the API is used.

BTW, the summary of this bug seems wrong, getElementById is only called once. It's either the node returned by createElement or by createTextNode that is invalid as an argument to appendChild.
gcast-logging.png
235 KB View Download

Comment 2 by sczs@chromium.org, May 9 2018

Cc: m...@chromium.org
Owner: olivierrobin@chromium.org
Status: Assigned (was: Untriaged)
olivierrobin@ could you PTAL?
ccing miu@ since he seems to be working on Cast
The tag is iOS but the text is mac and linux.
mfoltz@, is it mac or iOS?
It was reported originally on iOS.

Comment 5 by fergal@chromium.org, May 10 2018

Sorry, ignore the references to Mac, that was an error on my part (although I assume Mac would show the same behaviour as linux - no exception but weird output in the dev tools).
Cc: eugene...@chromium.org olivierrobin@chromium.org
Components: Mobile>WebView>Glue
Owner: michaeldo@chromium.org
Summary: Calling sendMessage from cross origin iframe throws a SecurityError. (was: when cast API becomes available DOM objects start to misbehave)
The issue is that codepen uses cross origin iFrames.
Code frame is https://s.codepen.io when window is https://codepen.io.

When the codepen tries to initialize cast, it calls invokeOnHost, and the first instruction is 
if (typeof window.top.__gCrWeb.windowId != 'string') {

which tries to do a cross origin call and throws the exception.
Does this bug represent a problem not seen on codepen.io? It looks like codepen can't be used on iOS due to cross origin iframe restrictions.

If I use the source from the codepen in comment #0 and put it into an html file (attached), it looks like this functions correctly on iOS.
codepen_result.html
1.2 KB View Download
The problem is seen with codepen.
If you load the page in 0, you get an error in the web inspector.

Comment 9 by syatam@google.com, May 14 2018

It looks like the problem is not with codepen. Below is another example which reproduces the bug on Chrome for iOS both on iPad and iPhone

The reason this didn't reproduce for you when taken off codepen is because for some reason now the google cast lib seems to finishing initialization before the window.onload event.

If it indeed finishes before we have any reference to a DOM node then everything's fine. If it finishes after then any previously referenced DOM node becomes invalid.

Please find attached better script illustrating the problem.

In the that script I'm getting a ref to the 'content' node on DOMContentLoaded, before the GCast is initialized, and then I'm checking the node's status within an interval.

A little after __onGCastApiAvailable is invoked the 'content' node becomes invalid.
example.html
653 bytes View Download

Comment 10 by syatam@google.com, May 30 2018

Any updates here?
Labels: -OS-Linux -Type-Bug -Pri-2 M-68 Pri-1 Type-Compat
Mike, let's try to fix this in M68. 
syatam@, thank you for the example script in comment #9. I tested this in the iOS simulator so that I could easily inspect the JS and I am able to reproduce the node becoming invalid.

However, I am not confident that the |instanceof Node| test is actually correct. I inspected bodyNode at the testNodesStatus alert and at the GCast loaded alert and it doesn't actually look like |bodyNode| is becoming invalid. Although the instanceof test fails, |bodyNode| still looks OK to me. Please see the attached screenshots of the debugger at each of these points.

(I am also no longer seeing a SecurityError in the console.)
cast_loaded.png
879 KB View Download
testNodeStatus.png
786 KB View Download
Cc: -syatam@google.com -fergal@chromium.org syatam@chromium.org michaeldo@chromium.org
Owner: mfo...@chromium.org
mfoltz@ or syatam@ are you still seeing this?
Cc: -syatam@chromium.org fergal@chromium.org syatam@google.com
(Fix CC'd members)
Cc: -m...@chromium.org
Cc: neosapien@google.com zivh@google.com
This may be related to Bug 889529.  In both cases the code loaded by cast_sender.js seems to be causing problems with DOM APIs.  I'm not really set up to debug this at the moment, but CCing two members of the Cast team who may want to see the data in this bug.


Components: Mobile>iOSWeb
Components: -Mobile>WebView>Glue
Components: -Mobile>iOSWeb Mobile>iOSWeb>ScriptInjections
Status: WontFix (was: Assigned)
I believe that this is no longer an issue, as Cast support has been removed from iOS (Bug 872050).

Sign in to add a comment