Skip to content

Commit a93b778

Browse files
authored
Fixing bug with Firefox extension content scripts (#2099)
1 parent 3c40492 commit a93b778

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

crates/js-sys/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4747,9 +4747,11 @@ pub fn global() -> Object {
47474747
fn get_global() -> Result<Object, JsValue>;
47484748
}
47494749

4750-
let static_object = Global::get_global_this()
4751-
.or_else(|_| Global::get_self())
4750+
// The order is important: in Firefox Extension Content Scripts `globalThis`
4751+
// is a Sandbox (not Window), so `globalThis` must be checked after `window`.
4752+
let static_object = Global::get_self()
47524753
.or_else(|_| Global::get_window())
4754+
.or_else(|_| Global::get_global_this())
47534755
.or_else(|_| Global::get_global());
47544756
if let Ok(obj) = static_object {
47554757
if !obj.is_undefined() {

0 commit comments

Comments
 (0)