Skip to content

Commit

Permalink
fix: issue fixed by replacing window with globalThis (#3026)
Browse files Browse the repository at this point in the history
* fix: issue fixed by replacing window with globalThis

* tests fixed

* tests fixed

* client tests fixed

* fix client tests

* fix client tests

* fix: client test fixed

* fix: server tests fixed

---------

Co-authored-by: Bayheck <[email protected]>
  • Loading branch information
Bayheck and Bayheck authored Nov 4, 2024
1 parent dfa3642 commit 535c7c1
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 60 deletions.
2 changes: 1 addition & 1 deletion gulp/saucelabs-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const CLIENT_TESTS_BROWSERS = [
{
browserName: 'Safari',
deviceName: 'iPhone 7 Plus Simulator',
platformVersion: '11.3',
platformVersion: '12.2',
platformName: 'iOS',
},
{
Expand Down
34 changes: 17 additions & 17 deletions src/processing/script/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (typeof importScripts !== "undefined" && /\\[native code]/g.test(importScript
}
`;

const PROCESS_DOM_METHOD = `window['${INTERNAL_PROPS.processDomMethodName}'] && window['${INTERNAL_PROPS.processDomMethodName}']();`;
const PROCESS_DOM_METHOD = `globalThis.window['${INTERNAL_PROPS.processDomMethodName}'] && globalThis.window['${INTERNAL_PROPS.processDomMethodName}']();`;

function trim (val: string): string {
return val.replace(/\n(?!$)\s*/g, '');
Expand All @@ -34,7 +34,7 @@ const NATIVE_AUTOMATION_HEADER = trim(`
${SCRIPT_PROCESSING_START_COMMENT}
${STRICT_MODE_PLACEHOLDER}
if (typeof window !== 'undefined' && window) {
if (typeof globalThis.window !== 'undefined' && globalThis.window) {
${PROCESS_DOM_METHOD}
}
Expand All @@ -46,23 +46,23 @@ const HEADER = trim(`
${STRICT_MODE_PLACEHOLDER}
${SW_SCOPE_HEADER_VALUE}
if (typeof window !== 'undefined' && window){
if (typeof globalThis.window !== 'undefined' && globalThis.window){
${PROCESS_DOM_METHOD}
if (window.${INSTRUCTION.getProperty} && typeof ${INSTRUCTION.getProperty} === 'undefined')
var ${INSTRUCTION.getLocation} = window.${INSTRUCTION.getLocation},
${INSTRUCTION.setLocation} = window.${INSTRUCTION.setLocation},
${INSTRUCTION.setProperty} = window.${INSTRUCTION.setProperty},
${INSTRUCTION.getProperty} = window.${INSTRUCTION.getProperty},
${INSTRUCTION.callMethod} = window.${INSTRUCTION.callMethod},
${INSTRUCTION.getEval} = window.${INSTRUCTION.getEval},
${INSTRUCTION.processScript} = window.${INSTRUCTION.processScript},
${INSTRUCTION.processHtml} = window.${INSTRUCTION.processHtml},
${INSTRUCTION.getPostMessage} = window.${INSTRUCTION.getPostMessage},
${INSTRUCTION.getProxyUrl} = window.${INSTRUCTION.getProxyUrl},
${INSTRUCTION.restArray} = window.${INSTRUCTION.restArray},
${INSTRUCTION.restObject} = window.${INSTRUCTION.restObject},
${INSTRUCTION.arrayFrom} = window.${INSTRUCTION.arrayFrom};
if (globalThis.window.${INSTRUCTION.getProperty} && typeof ${INSTRUCTION.getProperty} === 'undefined')
var ${INSTRUCTION.getLocation} = globalThis.window.${INSTRUCTION.getLocation},
${INSTRUCTION.setLocation} = globalThis.window.${INSTRUCTION.setLocation},
${INSTRUCTION.setProperty} = globalThis.window.${INSTRUCTION.setProperty},
${INSTRUCTION.getProperty} = globalThis.window.${INSTRUCTION.getProperty},
${INSTRUCTION.callMethod} = globalThis.window.${INSTRUCTION.callMethod},
${INSTRUCTION.getEval} = globalThis.window.${INSTRUCTION.getEval},
${INSTRUCTION.processScript} = globalThis.window.${INSTRUCTION.processScript},
${INSTRUCTION.processHtml} = globalThis.window.${INSTRUCTION.processHtml},
${INSTRUCTION.getPostMessage} = globalThis.window.${INSTRUCTION.getPostMessage},
${INSTRUCTION.getProxyUrl} = globalThis.window.${INSTRUCTION.getProxyUrl},
${INSTRUCTION.restArray} = globalThis.window.${INSTRUCTION.restArray},
${INSTRUCTION.restObject} = globalThis.window.${INSTRUCTION.restObject},
${INSTRUCTION.arrayFrom} = globalThis.window.${INSTRUCTION.arrayFrom};
} else {
if (typeof ${INSTRUCTION.getProperty} === 'undefined')
var ${INSTRUCTION.getLocation} = function(l){return l},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ module('getElementsByTagName', function () {
var elementsCount = 0;
var expectedProps = ['item', 'namedItem', 'length'];

if (browserUtils.isMacPlatform && browserUtils.isSafari)
if ((browserUtils.isMacPlatform || browserUtils.isIOS) && browserUtils.isSafari)
expectedProps.push('constructor');

for (var idx in collection) {
Expand Down
4 changes: 2 additions & 2 deletions test/server/data/cache/expected-script.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 18 additions & 16 deletions test/server/data/html-import-page/expected.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
<title></title>
<style type="text/css">/*hammerhead|stylesheet|start*/

.someRule {
background-image: url(http://127.0.0.1:1836/sessionId/http://some.url);
background: repeat-y url(http://127.0.0.1:1836/sessionId/http://base.url/some/other/url) #fc0;
}
.someRule {
background-image: url(http://127.0.0.1:1836/sessionId/http://some.url);
background: repeat-y url(http://127.0.0.1:1836/sessionId/http://base.url/some/other/url) #fc0;
}

/*hammerhead|stylesheet|end*/</style>
<script type="text/javascript">/*hammerhead|script|start*/if (typeof globalThis.window !== 'undefined' && globalThis.window){globalThis.window['hammerhead|process-dom-method'] && globalThis.window['hammerhead|process-dom-method']();if (globalThis.window.__get$ && typeof __get$ === 'undefined')var __get$Loc = globalThis.window.__get$Loc,__set$Loc = globalThis.window.__set$Loc,__set$ = globalThis.window.__set$,__get$ = globalThis.window.__get$,__call$ = globalThis.window.__call$,__get$Eval = globalThis.window.__get$Eval,__proc$Script = globalThis.window.__proc$Script,__proc$Html = globalThis.window.__proc$Html,__get$PostMessage = globalThis.window.__get$PostMessage,__get$ProxyUrl = globalThis.window.__get$ProxyUrl,__rest$Array = globalThis.window.__rest$Array,__rest$Object = globalThis.window.__rest$Object,__arrayFrom$ = globalThis.window.__arrayFrom$;} else {if (typeof __get$ === 'undefined')var __get$Loc = function(l){return l},__set$Loc = function(l,v){return l = v},__set$ = function(o,p,v){return o[p] = v},__get$ = function(o,p){return o[p]},__call$ = function(o,p,a){return o[p].apply(o,a)},__get$Eval = function(e){return e},__proc$Script = function(s){return s},__proc$Html = function(h){return h},__get$PostMessage = function(w,p){return arguments.length===1?w.postMessage:p},__get$ProxyUrl = function(u,d){return u},__rest$Array = function(a,i){return Array.prototype.slice.call(a, i)},__rest$Object = function(o,p){var k=Object.keys(o),n={};for(var i=0;i<k.length;++i)if(p.indexOf(k[i])<0)n[k[i]]=o[k[i]];return n},__arrayFrom$ = function(r){if(!r)return r;return!Array.isArray(r)&&"function"==typeof r[Symbol.iterator]?Array.from(r):r};if (typeof importScripts !== "undefined" && /\[native code]/g.test(importScripts.toString())) {var __getWorkerSettings$ = function () {return null};importScripts((location.origin || (location.protocol + "//" + location.host)) + "/worker-hammerhead.js");}}/*hammerhead|script|processing-header-end*/

/*hammerhead|stylesheet|end*/</style>
<script type="text/javascript">/*hammerhead|script|start*/if (typeof window !== "undefined" && window){window["hammerhead|process-dom-method"] && window["hammerhead|process-dom-method"]();if (window.__get$ && typeof __get$ === "undefined")var __get$Loc = window.__get$Loc,__set$Loc = window.__set$Loc,__set$ = window.__set$,__get$ = window.__get$,__call$ = window.__call$,__get$Eval = window.__get$Eval,__proc$Script = window.__proc$Script,__proc$Html = window.__proc$Html,__get$PostMessage = window.__get$PostMessage,__get$ProxyUrl = window.__get$ProxyUrl,__rest$Array = window.__rest$Array,__rest$Object = window.__rest$Object,__arrayFrom$ = window.__arrayFrom$;} else {if (typeof __get$ === "undefined")var __get$Loc = function(l){return l},__set$Loc = function(l,v){return l = v},__set$ = function(o,p,v){return o[p] = v},__get$ = function(o,p){return o[p]},__call$ = function(o,p,a){return o[p].apply(o,a)},__get$Eval = function(e){return e},__proc$Script = function(s){return s},__proc$Html = function(h){return h},__get$PostMessage = function(w,p){return arguments.length===1?w.postMessage:p},__get$ProxyUrl = function(u,d){return u},__rest$Array = function(a,i){return Array.prototype.slice.call(a, i)},__rest$Object = function(o,p){var k=Object.keys(o),n={};for(var i=0;i<k.length;++i)if(p.indexOf(k[i])<0)n[k[i]]=o[k[i]];return n},__arrayFrom$ = function(r){if(!r)return r;return!Array.isArray(r)&&"function"==typeof r[Symbol.iterator]?Array.from(r):r};if (typeof importScripts !== "undefined" && /\[native code]/g.test(importScripts.toString())) {var __getWorkerSettings$ = function () {return null};importScripts((location.origin || (location.protocol + "//" + location.host)) + "/worker-hammerhead.js");}}/*hammerhead|script|processing-header-end*/

{
a : __get$(window,"location")
}

/*hammerhead|script|end*/</script>
{
a : __get$(window,"location")
}

/*hammerhead|script|end*/</script>
<script type="text/javascript">
<!--//-->
<![CDATA[//><!--
Expand All @@ -31,10 +31,10 @@
<!-- T217636: Health monitor - script incorrectly processes html-comments (flipkart.com) -->
<script type="text/javascript">
<!--<script type="text/javascript">-->
/*hammerhead|script|start*/if (typeof window !== "undefined" && window){window["hammerhead|process-dom-method"] && window["hammerhead|process-dom-method"]();if (window.__get$ && typeof __get$ === "undefined")var __get$Loc = window.__get$Loc,__set$Loc = window.__set$Loc,__set$ = window.__set$,__get$ = window.__get$,__call$ = window.__call$,__get$Eval = window.__get$Eval,__proc$Script = window.__proc$Script,__proc$Html = window.__proc$Html,__get$PostMessage = window.__get$PostMessage,__get$ProxyUrl = window.__get$ProxyUrl,__rest$Array = window.__rest$Array,__rest$Object = window.__rest$Object,__arrayFrom$ = window.__arrayFrom$;} else {if (typeof __get$ === "undefined")var __get$Loc = function(l){return l},__set$Loc = function(l,v){return l = v},__set$ = function(o,p,v){return o[p] = v},__get$ = function(o,p){return o[p]},__call$ = function(o,p,a){return o[p].apply(o,a)},__get$Eval = function(e){return e},__proc$Script = function(s){return s},__proc$Html = function(h){return h},__get$PostMessage = function(w,p){return arguments.length===1?w.postMessage:p},__get$ProxyUrl = function(u,d){return u},__rest$Array = function(a,i){return Array.prototype.slice.call(a, i)},__rest$Object = function(o,p){var k=Object.keys(o),n={};for(var i=0;i<k.length;++i)if(p.indexOf(k[i])<0)n[k[i]]=o[k[i]];return n},__arrayFrom$ = function(r){if(!r)return r;return!Array.isArray(r)&&"function"==typeof r[Symbol.iterator]?Array.from(r):r};if (typeof importScripts !== "undefined" && /\[native code]/g.test(importScripts.toString())) {var __getWorkerSettings$ = function () {return null};importScripts((location.origin || (location.protocol + "//" + location.host)) + "/worker-hammerhead.js");}}/*hammerhead|script|processing-header-end*/
/*hammerhead|script|start*/if (typeof globalThis.window !== 'undefined' && globalThis.window){globalThis.window['hammerhead|process-dom-method'] && globalThis.window['hammerhead|process-dom-method']();if (globalThis.window.__get$ && typeof __get$ === 'undefined')var __get$Loc = globalThis.window.__get$Loc,__set$Loc = globalThis.window.__set$Loc,__set$ = globalThis.window.__set$,__get$ = globalThis.window.__get$,__call$ = globalThis.window.__call$,__get$Eval = globalThis.window.__get$Eval,__proc$Script = globalThis.window.__proc$Script,__proc$Html = globalThis.window.__proc$Html,__get$PostMessage = globalThis.window.__get$PostMessage,__get$ProxyUrl = globalThis.window.__get$ProxyUrl,__rest$Array = globalThis.window.__rest$Array,__rest$Object = globalThis.window.__rest$Object,__arrayFrom$ = globalThis.window.__arrayFrom$;} else {if (typeof __get$ === 'undefined')var __get$Loc = function(l){return l},__set$Loc = function(l,v){return l = v},__set$ = function(o,p,v){return o[p] = v},__get$ = function(o,p){return o[p]},__call$ = function(o,p,a){return o[p].apply(o,a)},__get$Eval = function(e){return e},__proc$Script = function(s){return s},__proc$Html = function(h){return h},__get$PostMessage = function(w,p){return arguments.length===1?w.postMessage:p},__get$ProxyUrl = function(u,d){return u},__rest$Array = function(a,i){return Array.prototype.slice.call(a, i)},__rest$Object = function(o,p){var k=Object.keys(o),n={};for(var i=0;i<k.length;++i)if(p.indexOf(k[i])<0)n[k[i]]=o[k[i]];return n},__arrayFrom$ = function(r){if(!r)return r;return!Array.isArray(r)&&"function"==typeof r[Symbol.iterator]?Array.from(r):r};if (typeof importScripts !== "undefined" && /\[native code]/g.test(importScripts.toString())) {var __getWorkerSettings$ = function () {return null};importScripts((location.origin || (location.protocol + "//" + location.host)) + "/worker-hammerhead.js");}}/*hammerhead|script|processing-header-end*/
var someScript;

/*hammerhead|script|end*/</script>
/*hammerhead|script|end*/</script>
<link rel="import" href="http://127.0.0.1:1836/sessionId!h/http://link.url/some-imported-page.html" href-hammerhead-stored-value="http://link.url/some-imported-page.html">
</head>
<body>
Expand All @@ -43,4 +43,6 @@
<form id="form" method="post" action="http://127.0.0.1:1836/sessionId!f/http://post.something.here" action-hammerhead-stored-value="http://post.something.here">
<button formaction="http://127.0.0.1:1836/sessionId!f/http://button.formaction.com/" formaction-hammerhead-stored-value="http://button.formaction.com/"></button>
</form>
</body></html>


</body></html>
Loading

0 comments on commit 535c7c1

Please sign in to comment.