Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid doc.write if a 3p frame has already been instrumented #9176

Merged
merged 2 commits into from
May 10, 2017

Conversation

lannka
Copy link
Contributor

@lannka lannka commented May 5, 2017

Fixes #9249

@cramforce , do you remember why we had the instrumentDocWrite code?

doc.write('<script>window.parent.ampManageWin(window)</script>'); is making ads blank.
(we might override doc.close too late?)

screen shot 2017-05-05 at 3 53 42 pm

@lannka lannka requested a review from cramforce May 5, 2017 22:32
@lannka lannka requested a review from dvoytenko May 5, 2017 22:33
@jridgewell
Copy link
Contributor

Bad ads installing video stream decoding JS.

@lannka
Copy link
Contributor Author

lannka commented May 5, 2017

@jridgewell why manageWin is not enough and we have to instrumentDocWrite?

@lannka
Copy link
Contributor Author

lannka commented May 5, 2017

@jridgewell don't quite understand your point.

@jridgewell
Copy link
Contributor

It's another defense against badly written code.

@lannka
Copy link
Contributor Author

lannka commented May 5, 2017

the mystery to me is that we already did manageWin(iframe.contentWindow) immediately when we saw a new iframe window. but for some reasons, we did the same thing again and again at different time:

  1. iframe.onload = function () { /* one time here */}
  2. iframe.contentWindow.document.close = function () { /* one more time here */}

In my local test, I found 1) is necessary, though I don't have explanation. In fact, when I try to debug, it becomes unnecessary.
2) seems to be not needed, or maybe I wasn't using an appropriate test case.

So really want to hear from @cramforce who introduced those hacks :-). What problems were there?

@@ -178,13 +142,15 @@ function instrumentEntryPoints(win) {
// Change setTimeout to respect a minimum timeout.
const setTimeout = win.setTimeout;
win.setTimeout = function(fn, time) {
dev().info('SETTIMEOUT', win.name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DO NOT SUBMIT?

@dvoytenko
Copy link
Contributor

@lannka Do we know the reason why it breaks anything, however?

@cramforce
Copy link
Member

Are we running the code twice on the same window. There is a case of removing all of this code now that browsers throttle themselves more aggressively.

@lannka
Copy link
Contributor Author

lannka commented May 9, 2017

@lannka Do we know the reason why it breaks anything, however?

@dvoytenko as I mentioned in PR description

doc.write('<script>window.parent.ampManageWin(window)</script>'); is making ads blank.
(we might override doc.close too late?)

See that screenshot.

Are we running the code twice on the same window. There is a case of removing all of this code now that browsers throttle themselves more aggressively.

@cramforce No. manageWin() is flag protected (window.ampSeen). However, the doc.write is not. I can do

if (!parent.ampSeen) {
  doc.write('<script>window.parent.ampManageWin(window)</script>');		
}

But I want to understand what corner case this code is trying to handle, can we get rid of them completely? At least the doc.write part, which seems dangerous.

@cramforce
Copy link
Member

That conditional should definitely be added!!

There are many ways how iframes are added to ad pages. This is handling one of those cases. Might or might not be needed for doubleclick.

@lannka
Copy link
Contributor Author

lannka commented May 10, 2017

@cramforce adding the check fixes the issue. this is good for now, let's follow up offline see if we can improve some of the code here.

Copy link
Member

@cramforce cramforce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is cool, but the PR description doesn't correctly reflect it.

@lannka lannka changed the title Remove doc.write while instrumenting 3p frame. Avoid doc.write if a 3p frame has already been instrumented May 10, 2017
@lannka
Copy link
Contributor Author

lannka commented May 10, 2017

updated description

@lannka lannka merged commit 06bdb85 into ampproject:master May 10, 2017
@lannka lannka deleted the 3p-instrument-iframe branch May 10, 2017 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blank ads caused by doc.write in environment.js
6 participants