patchright-core 1.55.1 → 1.55.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -127,9 +127,7 @@ class BrowserContext extends import_instrumentation.SdkObject {
|
|
|
127
127
|
`);
|
|
128
128
|
}
|
|
129
129
|
if (this._options.serviceWorkers === "block")
|
|
130
|
-
await this.addInitScript(`navigator.serviceWorker.register = async () => { }
|
|
131
|
-
if (navigator.serviceWorker) navigator.serviceWorker.register = async () => { console.warn('Service Worker registration blocked by Playwright'); };
|
|
132
|
-
`);
|
|
130
|
+
await this.addInitScript(void 0, `navigator.serviceWorker.register = async () => { };`);
|
|
133
131
|
if (this._options.permissions)
|
|
134
132
|
await this.grantPermissions(this._options.permissions);
|
|
135
133
|
}
|
|
@@ -568,8 +568,20 @@ class RouteImpl {
|
|
|
568
568
|
response.isBase64 = false;
|
|
569
569
|
response.body = Buffer.from(response.body, "base64").toString("utf-8");
|
|
570
570
|
}
|
|
571
|
-
|
|
572
|
-
|
|
571
|
+
const headMatch = response.body.match(/<head[^>]*>[\s\S]*?<\/head>/i);
|
|
572
|
+
if (headMatch) {
|
|
573
|
+
response.body = response.body.replace(/(<head[^>]*>)([\s\S]*?)(<\/head>)/i, (match, headOpen, headContent, headClose) => {
|
|
574
|
+
const scriptMatch = headContent.match(/([\s\S]*?)(<script[\s\S]*?$)/i);
|
|
575
|
+
if (scriptMatch) {
|
|
576
|
+
const [beforeScript, fromScript] = [scriptMatch[1], scriptMatch[2]];
|
|
577
|
+
return `${headOpen}${beforeScript}${injectionHTML}${fromScript}${headClose}`;
|
|
578
|
+
}
|
|
579
|
+
return `${headOpen}${headContent}${injectionHTML}${headClose}`;
|
|
580
|
+
});
|
|
581
|
+
} else if (/^<!DOCTYPE[\s\S]*?>/i.test(response.body)) {
|
|
582
|
+
response.body = response.body.replace(/^<!DOCTYPE[\s\S]*?>/i, (match) => `${match}${injectionHTML}`);
|
|
583
|
+
} else if (/<html[^>]*>/i.test(response.body)) {
|
|
584
|
+
response.body = response.body.replace(/<html[^>]*>/i, `$&<head>${injectionHTML}</head>`);
|
|
573
585
|
} else {
|
|
574
586
|
response.body = injectionHTML + response.body;
|
|
575
587
|
}
|
|
@@ -64,6 +64,16 @@ class CRServiceWorker extends import_page.Worker {
|
|
|
64
64
|
session.on("Inspector.targetReloadedAfterCrash", () => {
|
|
65
65
|
session._sendMayFail("Runtime.runIfWaitingForDebugger", {});
|
|
66
66
|
});
|
|
67
|
+
session._sendMayFail("Runtime.evaluate", {
|
|
68
|
+
expression: "globalThis",
|
|
69
|
+
serializationOptions: { serialization: "idOnly" }
|
|
70
|
+
}).then((globalThis) => {
|
|
71
|
+
if (globalThis && globalThis.result) {
|
|
72
|
+
var globalThisObjId = globalThis.result.objectId;
|
|
73
|
+
var executionContextId = parseInt(globalThisObjId.split(".")[1], 10);
|
|
74
|
+
this.createExecutionContext(new import_crExecutionContext.CRExecutionContext(session, { id: executionContextId }));
|
|
75
|
+
}
|
|
76
|
+
});
|
|
67
77
|
}
|
|
68
78
|
didClose() {
|
|
69
79
|
this._networkManager?.removeSession(this._session);
|
package/lib/server/frames.js
CHANGED
|
@@ -1603,7 +1603,8 @@ class Frame extends import_instrumentation.SdkObject {
|
|
|
1603
1603
|
const partNth = Number(part.body);
|
|
1604
1604
|
if (currentScopingElements.length == 0) return [];
|
|
1605
1605
|
if (partNth > currentScopingElements.length - 1 || partNth < -(currentScopingElements.length - 1)) {
|
|
1606
|
-
throw new Error("Can't query n-th element");
|
|
1606
|
+
if (parsed.capture !== void 0) throw new Error("Can't query n-th element in a request with the capture.");
|
|
1607
|
+
return [];
|
|
1607
1608
|
} else {
|
|
1608
1609
|
currentScopingElements = [currentScopingElements.at(partNth)];
|
|
1609
1610
|
continue;
|
|
@@ -1692,24 +1693,27 @@ class Frame extends import_instrumentation.SdkObject {
|
|
|
1692
1693
|
depth: -1
|
|
1693
1694
|
});
|
|
1694
1695
|
elementToCheck.backendNodeId = resolvedElement.node.backendNodeId;
|
|
1696
|
+
elementToCheck.nodePosition = this.selectors._findElementPositionInDomTree(elementToCheck, describedScope.node, context, "");
|
|
1695
1697
|
elements.push(elementToCheck);
|
|
1696
1698
|
}
|
|
1697
1699
|
}
|
|
1698
1700
|
}
|
|
1699
1701
|
}
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
currentScopingElements.splice(elemPos, 0, element);
|
|
1710
|
-
elementsIndexes.splice(elemPos, 0, elemIndex);
|
|
1702
|
+
const getParts = (pos) => (pos || "").split("").map(Number);
|
|
1703
|
+
elements.sort((a, b) => {
|
|
1704
|
+
const partA = getParts(a.nodePosition);
|
|
1705
|
+
const partB = getParts(b.nodePosition);
|
|
1706
|
+
const maxLength = Math.max(partA.length, partB.length);
|
|
1707
|
+
for (let i2 = 0; i2 < maxLength; i2++) {
|
|
1708
|
+
const aVal = partA[i2] ?? -1;
|
|
1709
|
+
const bVal = partB[i2] ?? -1;
|
|
1710
|
+
if (aVal !== bVal) return aVal - bVal;
|
|
1711
1711
|
}
|
|
1712
|
-
|
|
1712
|
+
return 0;
|
|
1713
|
+
});
|
|
1714
|
+
currentScopingElements = Array.from(
|
|
1715
|
+
new Map(elements.map((e) => [e.backendNodeId, e])).values()
|
|
1716
|
+
);
|
|
1713
1717
|
}
|
|
1714
1718
|
return currentScopingElements;
|
|
1715
1719
|
}
|