Skip to content

Commit c67fbf8

Browse files
committed
fix(emulators): wait for doc element
1 parent a699212 commit c67fbf8

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

emulator-plugins/shared/injected-scripts/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ function buildExecutionScript(name: string, script: string, args?: any) {
2222
${utilsScript}
2323
2424
// documentElement is not loaded
25-
if ('${name}' === 'polyfill') {
26-
while (!document.documentElement) {
27-
await new Promise(resolve => setTimeout(resolve, 10));
28-
}
25+
if ('${name}' === 'polyfill' && !document.documentElement) {
26+
await new Promise(resolve => {
27+
new MutationObserver((list, observer) => {
28+
resolve();
29+
observer.disconnect();
30+
}).observe(document, {childList: true, subtree: true});
31+
});
2932
}
3033
3134
(function ${name}(args) {

emulator-plugins/shared/injected-scripts/polyfill.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
for (const remove of args.removals) {
1+
for (const remove of args.removals || []) {
22
try {
33
const parts = getParentAndProperty(remove);
44
delete parts.parent[parts.property];
@@ -7,7 +7,7 @@ for (const remove of args.removals) {
77
}
88
}
99

10-
for (const addition of args.additions) {
10+
for (const addition of args.additions || []) {
1111
try {
1212
if (addition.propertyName === 'getVideoPlaybackQuality') {
1313
addition.property['_value()'] = function() {
@@ -28,7 +28,7 @@ for (const addition of args.additions) {
2828
}
2929
}
3030

31-
for (const change of args.changes) {
31+
for (const change of args.changes || []) {
3232
try {
3333
if (change.propertyName === '_function') {
3434
const func = getObjectAtPath(change.path);
@@ -67,7 +67,7 @@ for (const change of args.changes) {
6767
}
6868

6969
function reorder() {
70-
for (const { propertyName, prevProperty, throughProperty, path } of args.order) {
70+
for (const { propertyName, prevProperty, throughProperty, path } of args.order || []) {
7171
try {
7272
if (!path.includes('.prototype')) {
7373
reorderOnWindow(path, propertyName, prevProperty, throughProperty);

jest.teardown.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
const fs = require('fs');
2+
const os = require('os');
3+
const { execSync } = require('child_process');
24

35
module.exports = async () => {
46
try {
7+
if (os.platform() === 'win32') {
8+
execSync(`TASKKILL /IM chrome.exe /F`);
9+
}
510
fs.rmdirSync(`${__dirname}/.cache-test`, { recursive: true });
611
} catch (err) {}
712
};

0 commit comments

Comments
 (0)