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

Issue 733288 link

Starred by 5 users

Issue metadata

Status: Untriaged
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 1
Type: Bug-Regression



Sign in to add a comment

Redirect in head causes content scripts to be run with unfinished DOM

Reported by aja...@gmail.com, Jun 14 2017

Issue description

UserAgent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36

Steps to reproduce the problem:
1. Open the attached HTML file while the attached extension is active.
2. The file is set to redirect to itself half of the time, randomly, for ease of testing. If it does not redirect the first time, just reload the page until it does.
3. After it stops redirecting (or while it's redirecting), check the console. The content script is run on a page that claims to be loaded, but does not have a <body>. Also, the console output from the content script is not cleared when the page reloads.
4. Also note that the final iteration of the content script, run on a page that does not redirect, has a <body> as expected.

What is the expected behavior?
If a page is never going to finish loading, the content script should not be run at all, if the script's manifest requires that it be run *after* the DOM has loaded. Alternatively, the page should finish loading so that content scripts may be run on a valid DOM. At the very least, provide the script with a correct document.readyState.

What went wrong?
If a page or frame uses JS to redirect itself in the <head> tag, the page never gets as far as processing the <body> tag, but any content scripts are run anyway. They are given a readyState that indicates the DOM has loaded, even though it is in an invalid state. Additionally, the console output of such scripts is not cleared by the refresh.

Did this work before? N/A 

Does this work in other browsers? N/A

Chrome version: 58.0.3029.110  Channel: n/a
OS Version: 6.3
Flash Version: N/A
 
redirect_test.html
133 bytes View Download
RedirectTestExtension.zip
1.1 KB Download

Comment 1 by mmenke@chromium.org, Jun 14 2017

Components: Platform>Extensions

Comment 2 by woxxom@gmail.com, Jun 15 2017

Can you link the specification article saying that completeness of DOM requires presence of BODY tag? AFAIK a body-less DOM is valid.

Comment 3 by aja...@gmail.com, Jun 15 2017

Yes, "invalid" was probably a poor choice of words. While having a null body is valid,
1. Chrome creates an empty body DOM element even if none is included in the HTML, so this behavior is at least inconsistent.
2. The ready state claims that the DOM is fully loaded, even though any DOM from the body is not loaded. This is against the spec.
3. The Chrome extension run_at spec also claims that the DOM will be loaded before the content script is run.
4. The console output from the orphaned script is not cleared when the page location changes.
Labels: Needs-Milestone

Comment 5 by ajha@chromium.org, Jun 23 2017

Cc: ajha@chromium.org
Labels: -Type-Bug -Pri-2 -Needs-Milestone hasbisect-per-revision M-61 Pri-1 Type-Bug-Regression
Owner: kozyatinskiy@chromium.org
Status: Assigned (was: Unconfirmed)
Able to reproduce the issue on the latest canary(61.0.3139.0) on Windows-10. Seems to be working fine on the same chrome version on Mac OS 10.12.5 and Linux Ubuntu 14.04.

Regressed in M-57.

Last good build: 57.0.2946.0
First bad build: 57.0.2947.0 

Changelog:
==========
https://chromium.googlesource.com/chromium/src/+log/daaaf8661aa98f3f3eaa69a30816c2fae4f32704..a90a5a2ae73dfc8b362097077dc899d76b89e43d

kozyatinskiy@: Could you please take a look at this.

Thank you!

Note: Attached is the screenshot of the console observed on multiple refresh of the attached test page.
733288_Actual.png
19.6 KB View Download
Status: Untriaged (was: Assigned)
It's definitely not mine CL, my CL only change console output in DevTools and doesn't touch anything in extensions.
Untriaged for further triage.
Cc: kozyatinskiy@chromium.org
Owner: ----

Sign in to add a comment