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
#192)

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 authored Jan 6, 2025
1 parent d498c75 commit 351e8dc
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 351e8dc

Please sign in to comment.