Skip to content

Commit bd6d3e3

Browse files
BayheckBayheckCopilot
authored
fix: issue with module workers (#3046)
* fix: issue with module workers * fix: code clean * Update src/processing/script/header.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/processing/script/header.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/processing/script/header.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: comments removed from script * fix: server test updated * fix: server test updated * fix: server test updated * fix: test fixed * fix: server tests fixed * fix: code refactored * tests: fixed * tests: fixed expected scripts * tests: clear code * fix: note added to header script --------- Co-authored-by: Bayheck <adil.rakhaliyev@devexpress.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 5292f1a commit bd6d3e3

File tree

8 files changed

+20
-15
lines changed

8 files changed

+20
-15
lines changed

src/processing/script/header.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ const STRICT_MODE_PLACEHOLDER = '{strict-placeholder}';
1717
const SW_SCOPE_HEADER_VALUE = '{sw-scope-header-value}';
1818
const WORKER_SETTINGS_PLACEHOLDER = '{worker-settings}';
1919

20+
// NOTE: we need try/catch if a worker with ES module (fix for https://github.com/DevExpress/testcafe/issues/8251)
2021
const IMPORT_WORKER_HAMMERHEAD = `
2122
if (typeof importScripts !== "undefined" && /\\[native code]/g.test(importScripts.toString())) {
2223
var ${INSTRUCTION.getWorkerSettings} = function () {return ${WORKER_SETTINGS_PLACEHOLDER}};
23-
importScripts((location.origin || (location.protocol + "//" + location.host)) + "${SERVICE_ROUTES.workerHammerhead}");
24+
try {
25+
importScripts((location.origin || (location.protocol + "//" + location.host)) + "${SERVICE_ROUTES.workerHammerhead}");
26+
} catch (e) {
27+
(async function () { await import((location.origin || (location.protocol + "//" + location.host)) + "${SERVICE_ROUTES.workerHammerhead}"); })();
28+
}
2429
}
2530
`;
2631

test/server/data/cache/expected-script.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/server/data/html-import-page/expected.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
}
1515

1616
/*hammerhead|stylesheet|end*/</style>
17-
<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,opt=false){return opt&&(o===undefined||o===null)?undefined: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*/
17+
<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,opt=false){return opt&&(o===undefined||o===null)?undefined: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};try {importScripts((location.origin || (location.protocol + "//" + location.host)) + "/worker-hammerhead.js");} catch (e) {(async function () { await import((location.origin || (location.protocol + "//" + location.host)) + "/worker-hammerhead.js"); })();}}}/*hammerhead|script|processing-header-end*/
1818

1919
{
2020
a : __get$(window,"location")
@@ -31,7 +31,7 @@
3131
<!-- T217636: Health monitor - script incorrectly processes html-comments (flipkart.com) -->
3232
<script type="text/javascript">
3333
<!--<script type="text/javascript">-->
34-
/*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,opt=false){return opt&&(o===undefined||o===null)?undefined: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*/
34+
/*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,opt=false){return opt&&(o===undefined||o===null)?undefined: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};try {importScripts((location.origin || (location.protocol + "//" + location.host)) + "/worker-hammerhead.js");} catch (e) {(async function () { await import((location.origin || (location.protocol + "//" + location.host)) + "/worker-hammerhead.js"); })();}}}/*hammerhead|script|processing-header-end*/
3535
var someScript;
3636

3737
/*hammerhead|script|end*/</script>

0 commit comments

Comments
 (0)