Skip to content

Commit

Permalink
Fix Safari compatibility by applying window context to getter function
Browse files Browse the repository at this point in the history
The issue was identified using the rule: #%#//scriptlet('set-constant', 'navigator.privateAttribution', 'undefined'). Safari was throwing the error: "TypeError: The Window.navigator getter can only be used on instances of Window," which caused subsequent attempts to access the property to fail.
This commit resolves the issue by invoking the previous getter with this explicitly set to window.
  • Loading branch information
anfragment committed Jan 6, 2025
1 parent c635ea9 commit 9075a8e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/scriptlet/bundle.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion scriptlets/src/set-constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ export function setConstant(
get: () => {
let capturedValue;
if (typeof prevGetter === 'function') {
capturedValue = prevGetter();
// On certain properties, Safari wants window getters to be called with "window" as "this".
// Therefore, we apply instead of doing a regular function call.
capturedValue = prevGetter.apply(window);
} else {
capturedValue = window[localKey];
}
Expand Down

0 comments on commit 9075a8e

Please sign in to comment.