You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
User scripts don't apply correctly in about:blank #15082
Our implementation of user scripts appends <script src='file://...'></script> to the <head> element in every document is parsed. This breaks the synchronous nature of about:blank, since that's an asynchronous network request that interrupts parsing. I have a patch that embeds the user script source as an inline script instead.
diff --git a/components/script/dom/userscripts.rs b/components/script/dom/userscripts.rs
index 66758af..16a1b61 100644
--- a/components/script/dom/userscripts.rs+++ b/components/script/dom/userscripts.rs@@ -5,14 +5,15 @@
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::inheritance::Castable;
-use dom::bindings::js::RootedReference;+use dom::bindings::js::{RootedReference, Root};
use dom::bindings::str::DOMString;
use dom::htmlheadelement::HTMLHeadElement;
use dom::node::Node;
use servo_config::opts;
use servo_config::resource_files::resources_dir_path;
use std::borrow::ToOwned;
-use std::fs::read_dir;+use std::fs::{File, read_dir};+use std::io::Read;
use std::path::PathBuf;
@@ -40,12 +41,18 @@ pub fn load_script(head: &HTMLHeadElement) {
files.sort();
for file in files {
- let name = match file.into_os_string().into_string() {+ /*let name = match file.into_os_string().into_string() {
Ok(ref s) if s.ends_with(".js") => "file://".to_owned() + &s[..],
_ => continue
- };+ };*/+ //let name = file.into_os_string().into+ let mut f = File::open(&file).unwrap();+ let mut contents = vec![];+ f.read_to_end(&mut contents).unwrap();
let new_script = doc.CreateElement(DOMString::from("script")).unwrap();
- new_script.set_string_attribute(&local_name!("src"), DOMString::from(name));+ let script_text = Root::upcast(doc.CreateTextNode(String::from_utf8(contents).unwrap().into()));+ new_script.upcast::<Node>().AppendChild(&*script_text).unwrap();+ //new_script.set_string_attribute(&local_name!("src"), DOMString::from(name));
node.InsertBefore(new_script.upcast(), first_child.r()).unwrap();
}
}
The best way to test this change:
Modify resources/user-agent-js/00.example.js to contain window.foo = 'success!';, then run ./mach run test.html --userscripts, where test.html is a page like:
Activity
jdm commentedon Jan 17, 2017
Ms2ger commentedon Jan 19, 2017
At this point, why not just call
evaluate_js_scriptor whatever it's called?jdm commentedon Jan 19, 2017
That's... a good point!
highfive commentedon Feb 8, 2017
Hi! If you have any questions regarding this issue, feel free to make a comment here, or ask it in the
#servochannel in IRC.If you intend to work on this issue, then add
@highfive: assign meto your comment, and I'll assign this to you. 😄jdm commentedon Feb 8, 2017
The best way to test this change:
Modify
resources/user-agent-js/00.example.jsto containwindow.foo = 'success!';, then run./mach run test.html --userscripts, where test.html is a page like:The output should be:
but on master right now I see
jdm commentedon Feb 8, 2017
We'll want to call
GlobalScope::evaluate_js_on_global_with_resultinstead of appending a<script>element to the document.meetmangukiya commentedon Feb 12, 2017
@highfive: assign me
highfive commentedon Feb 12, 2017
Hey @meetmangukiya! Thanks for your interest in working on this issue. It's now assigned to you!
jdm commentedon Mar 4, 2017
Unassigning due to inactivity.
dudelson commentedon Mar 4, 2017
@highfive: assign me
highfive commentedon Mar 4, 2017
Hey @dudelson! Thanks for your interest in working on this issue. It's now assigned to you!
dudelson commentedon Mar 8, 2017
Although I would like to work on this issue, I've become too busy to complete it at this time. Please unassign me.
sendilkumarn commentedon Mar 8, 2017
@highfive: assign me
highfive commentedon Mar 8, 2017
Hey @sendilkumarn! Thanks for your interest in working on this issue. It's now assigned to you!
Auto merge of #15874 - sendilkumarn:user-script, r=nox