Bug 48970 - User scripts shouldn't be injected in a frame's empty initial document
Summary: User scripts shouldn't be injected in a frame's empty initial document
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Brian Weinstein
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2010-11-03 19:24 PDT by Brian Weinstein
Modified: 2011-04-06 04:17 PDT (History)
6 users (show)

See Also:


Attachments
[PATCH] Fix (10.87 KB, patch)
2010-11-03 19:59 PDT, Brian Weinstein
beidson: review+
bweinstein: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Weinstein 2010-11-03 19:24:46 PDT
When a frame loads, it first creates an empty initial document, then navigates to the correct URL. In WebKit2, the timing is slightly different than WebKit1, so when a new window or tab is created, start scripts are injected into the frame when it is about:blank, and then when it navigates to the correct URL.

This also happens when you inject scripts into all frames, iframes will look like they have had scripts injected twice - once with the URL being about:blank, and the other with the URL being the final URL of the frame. This is confusing to extension developers, and we shouldn't inject the scripts into the empty initial about:blank document.

<rdar://problem/8082122>
<rdar://problem/8618164>
Comment 1 Brian Weinstein 2010-11-03 19:59:36 PDT
Created attachment 72900 [details]
[PATCH] Fix
Comment 2 Alexey Proskuryakov 2010-11-03 20:16:51 PDT
User scripts will still be injected into about:blank, correct?
Comment 3 Brian Weinstein 2010-11-03 21:17:59 PDT
(In reply to comment #2)
> User scripts will still be injected into about:blank, correct?

Yes - userscripts/script-run-at-start.html tests that scripts are injected into about:blank.
Comment 4 Brian Weinstein 2010-11-04 09:40:44 PDT
Landed in r71339.
Comment 5 Timothy Hatcher 2010-11-04 09:44:21 PDT
Comment on attachment 72900 [details]
[PATCH] Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=72900&action=review

> WebCore/ChangeLog:10
> +        When a frame loads, it first creates an empty initial document, then navigates to the correct URL. Our

So <iframe src="about:blank"> will still work and get the content scripts once?

> WebCore/ChangeLog:15
> +        issue between WebKit1 and WebKit2 that causes start scripts to be injected into the initial empty document

Do we know what caused the timing issue between WK1 and WK2? Will that timing issue show up in other areas too?
Comment 6 Brian Weinstein 2010-11-04 09:50:37 PDT
(In reply to comment #5)
> (From update of attachment 72900 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=72900&action=review
> 
> > WebCore/ChangeLog:10
> > +        When a frame loads, it first creates an empty initial document, then navigates to the correct URL. Our
> 
> So <iframe src="about:blank"> will still work and get the content scripts once?

Yes - it will get end scripts once, and start scripts once. We have a test for this in the WebKit tree. userscripts/script-run-at-start.html tests that start scripts are injected into about:blank.

> 
> > WebCore/ChangeLog:15
> > +        issue between WebKit1 and WebKit2 that causes start scripts to be injected into the initial empty document
> 
> Do we know what caused the timing issue between WK1 and WK2? Will that timing issue show up in other areas too?

I haven't seen it come up in other areas - we believe it was a timing issue with the IPC - either the app was sending the user scripts across the wire earlier, or the web process was starting and loading the page later, and by that point the user scripts list wasn't empty.
Comment 7 Andy Estes 2011-04-06 04:17:57 PDT
What about apps that create a frame and then add nodes to the initial document using DOM API? We should be able to inject scripts into these documents, no?

I actually would like to use an injected script in this manner to fix <https://bugs.webkit.org/show_bug.cgi?id=57794>.