Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upUser scripts don't apply correctly in about:blank #15082
Comments
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();
}
} |
|
At this point, why not just call |
|
That's... a good point! |
|
Hi! If you have any questions regarding this issue, feel free to make a comment here, or ask it in the If you intend to work on this issue, then add |
|
The best way to test this change: <script>console.log(window.foo);</script>
<iframe></iframe>
<script>console.log(document.querySelector('iframe').contentWindow.foo);</script>The output should be:
but on master right now I see
|
|
We'll want to call |
|
@highfive: assign me |
|
Hey @meetmangukiya! Thanks for your interest in working on this issue. It's now assigned to you! |
|
@meetmangukiya Did you start working on this? |
|
Unassigning due to inactivity. |
|
@highfive: assign me |
|
Hey @dudelson! Thanks for your interest in working on this issue. It's now assigned to you! |
|
Although I would like to work on this issue, I've become too busy to complete it at this time. Please unassign me. |
|
@highfive: assign me |
|
Hey @sendilkumarn! Thanks for your interest in working on this issue. It's now assigned to you! |
apply user scripts correctly <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #15082 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15874) <!-- Reviewable:end -->
Our implementation of user scripts appends
<script src='file://...'></script>to the<head>element in every document is parsed. This breaks the synchronous nature ofabout: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.