diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs
index 0af076950b3..0b84bc38501 100644
--- a/components/script/dom/htmllinkelement.rs
+++ b/components/script/dom/htmllinkelement.rs
@@ -194,6 +194,10 @@ impl VirtualMethods for HTMLLinkElement {
impl HTMLLinkElement {
fn handle_stylesheet_url(&self, href: &str) {
let document = document_from_node(self);
+ if document.browsing_context().is_none() {
+ return;
+ }
+
match document.base_url().join(href) {
Ok(url) => {
let element = self.upcast::();