peachsim 0.1.687 → 0.1.689
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.
- package/cli/cloud-client.ts +3 -3
- package/cli/command-registry.ts +2 -0
- package/cli/commands/control.ts +1 -0
- package/cli/commands/debug.ts +10 -33
- package/cli/commands/do-chain.ts +56 -6
- package/cli/commands/inspect/core.ts +2 -0
- package/cli/commands/inspect/list.ts +2 -1
- package/cli/commands/inspect/settling.ts +17 -3
- package/cli/commands/inspect/shared.ts +2 -0
- package/cli/commands/inspect/wait-idle.ts +2 -2
- package/cli/commands/inspect/wait-ready.ts +3 -3
- package/cli/commands/inspect.ts +33 -7
- package/cli/commands/location.ts +164 -0
- package/cli/commands/platform.ts +1 -1
- package/cli/drivers/playwright-sim-host.ts +46 -25
- package/cli/main.ts +6 -0
- package/detox/index.ts +13 -8
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/agent-identity.cjs +1 -1
- package/dist-lib/agent-sessions.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +4 -3
- package/dist-lib/bridge-contract-input.cjs +12 -1
- package/dist-lib/bridge-contract-input.mjs +12 -1
- package/dist-lib/bridge-contract.cjs +4 -3
- package/dist-lib/bridge-contract.mjs +4 -3
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cli-constants.cjs +1 -1
- package/dist-lib/cloud-contract.cjs +2 -1
- package/dist-lib/cloud-contract.mjs +2 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +2 -1
- package/dist-lib/cloud.mjs +2 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/detox/index.cjs +1197 -65
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +362 -108
- package/dist-lib/host/fetch-proxy-handler.cjs +50 -40
- package/dist-lib/host/fetch-proxy-overrides.cjs +50 -6
- package/dist-lib/host/fetch-proxy-overrides.mjs +48 -5
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +29 -11
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +89 -13
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +5 -3
- package/dist-lib/native-app-identity.cjs +8 -3
- package/dist-lib/native-app-identity.mjs +8 -3
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/render-mode.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +2 -2
- package/dist-lib/sdk.cjs +21 -6
- package/dist-lib/sdk.mjs +21 -6
- package/dist-lib/skills.cjs +401 -130
- package/dist-lib/swift-compile.cjs +277 -22
- package/dist-lib/swift-compile.mjs +275 -22
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +2 -2
- package/dist-lib/swift-submit.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +10 -10
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +280 -44
- package/dist-lib/vite.cjs +1 -1
- package/kotlin/AppSources/android/content/res/Configuration.kt +2 -0
- package/kotlin/AppSources/android/content/res/Resources.kt +6 -3
- package/kotlin/AppSources/android/util/DisplayMetrics.kt +12 -0
- package/kotlin/AppSources/androidx/compose/ui/res/PainterResources.kt +70 -0
- package/kotlin/AppSources/dev/peach/app/PeachApp.kt +12 -10
- package/kotlin/AppSources/dev/peach/app/PeachDrawable.kt +95 -0
- package/kotlin/fixtures/kotlin-app-variants/Bitmaps.kt +50 -0
- package/kotlin/fixtures/kotlin-app-variants/Drawables.kt +53 -0
- package/package.json +2 -2
- package/scripts/dev-server-scanner.ts +3 -1
- package/skills/contrast/SKILL.md +1 -0
- package/src/android-drawables.ts +315 -0
- package/src/android-theme.ts +9 -0
- package/src/bridge-constants.ts +3 -2
- package/src/bridge-contract-input.ts +11 -0
- package/src/bridge-contract.ts +45 -3
- package/src/cloud-contract.ts +1 -0
- package/src/host/fetch-proxy-handler.ts +13 -49
- package/src/host/fetch-proxy-overrides.ts +69 -12
- package/src/kotlin-app.ts +6 -0
- package/src/kotlin-host.ts +103 -15
- package/src/native-app-identity.ts +16 -3
- package/src/swift-compile.ts +366 -24
- package/src/swift-distribution-contract.ts +11 -4
- package/src/swift-distribution.lock.json +11 -9
- package/src/swift-distribution.ts +4 -4
- package/src/swift-icu.ts +8 -11
- package/src/swift-submit.ts +13 -1
- package/src/swift-toolchain.ts +17 -9
- package/src/vite-plugin.ts +86 -34
package/dist-lib/detox/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! rnx v0.1.
|
|
1
|
+
/*! rnx v0.1.689 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
2
|
let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
|
|
3
3
|
"use strict";
|
|
4
4
|
var __create = Object.create;
|
|
@@ -237,6 +237,7 @@ __export(detox_exports, {
|
|
|
237
237
|
waitForSootsimShellReady: () => waitForSootsimShellReady
|
|
238
238
|
});
|
|
239
239
|
module.exports = __toCommonJS(detox_exports);
|
|
240
|
+
var import_crypto = require("crypto");
|
|
240
241
|
var fs = __toESM(require("fs"), 1);
|
|
241
242
|
var path = __toESM(require("path"), 1);
|
|
242
243
|
var import_playwright = require("playwright");
|
|
@@ -600,7 +601,7 @@ var PLAYWRIGHT_DISABLED_FEATURES = [
|
|
|
600
601
|
"msEdgeUpdateLaunchServicesPreferredVersion"
|
|
601
602
|
];
|
|
602
603
|
var PLAYWRIGHT_ENABLED_FEATURES = ["CDPScreenshotNewSurface"];
|
|
603
|
-
var DISABLED_FEATURES = ["NetworkTimeServiceQuerying"];
|
|
604
|
+
var DISABLED_FEATURES = ["NetworkTimeServiceQuerying", "LocalNetworkAccessChecks"];
|
|
604
605
|
function mergeFeatureSwitches(args, enabled = []) {
|
|
605
606
|
const enable = /* @__PURE__ */ new Set([...PLAYWRIGHT_ENABLED_FEATURES, ...enabled]);
|
|
606
607
|
const disable = /* @__PURE__ */ new Set([...PLAYWRIGHT_DISABLED_FEATURES, ...DISABLED_FEATURES]);
|
|
@@ -835,29 +836,144 @@ function readBrowserCompositeCaptureRequest(value) {
|
|
|
835
836
|
return request;
|
|
836
837
|
}
|
|
837
838
|
|
|
838
|
-
// ../peach-engine/src/
|
|
839
|
-
var
|
|
840
|
-
var
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
const
|
|
848
|
-
|
|
849
|
-
});
|
|
850
|
-
const pending = { owner, resolve };
|
|
851
|
-
readiness.set(identity, pending);
|
|
852
|
-
return pending;
|
|
839
|
+
// ../peach-engine/src/webview-automation-host.ts
|
|
840
|
+
var WEBVIEW_INSTANCE_ATTRIBUTE = "data-peach-webview";
|
|
841
|
+
var WEBVIEW_HOST_BINDING = "__peachWebViewHost";
|
|
842
|
+
var WEBVIEW_SCHEME_NAVIGATION_EVENT = "peach:webview-scheme-navigation";
|
|
843
|
+
var WEBVIEW_FRAME_NAME_PREFIX = "peach-webview:";
|
|
844
|
+
function readWebViewHostRequest(value) {
|
|
845
|
+
if (!value || typeof value !== "object") return null;
|
|
846
|
+
const field = (name2) => Reflect.get(value, name2);
|
|
847
|
+
const text = (name2) => {
|
|
848
|
+
const entry = field(name2);
|
|
849
|
+
return typeof entry === "string" ? entry : null;
|
|
853
850
|
};
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
851
|
+
const instanceId = text("instanceId");
|
|
852
|
+
if (instanceId === null) return null;
|
|
853
|
+
const kind = field("kind");
|
|
854
|
+
if (kind === "detach") return { kind, instanceId };
|
|
855
|
+
if (kind === "evaluate") {
|
|
856
|
+
const js = text("js");
|
|
857
|
+
return js === null ? null : { kind, instanceId, js };
|
|
858
|
+
}
|
|
859
|
+
if (kind === "tap") {
|
|
860
|
+
const x = field("x");
|
|
861
|
+
const y = field("y");
|
|
862
|
+
return typeof x === "number" && typeof y === "number" ? { kind, instanceId, x, y } : null;
|
|
863
|
+
}
|
|
864
|
+
if (kind !== "attach") return null;
|
|
865
|
+
const frameName = text("frameName");
|
|
866
|
+
const url = text("url");
|
|
867
|
+
const config = text("config");
|
|
868
|
+
const beforeKey = text("beforeKey");
|
|
869
|
+
const beforeContent = text("beforeContent");
|
|
870
|
+
const afterContent = text("afterContent");
|
|
871
|
+
const incognito = field("incognito");
|
|
872
|
+
const rawHeaders = field("headers");
|
|
873
|
+
if (frameName === null || url === null || config === null || beforeKey === null || beforeContent === null || afterContent === null || typeof incognito !== "boolean" || !rawHeaders || typeof rawHeaders !== "object") {
|
|
874
|
+
return null;
|
|
875
|
+
}
|
|
876
|
+
const headers = {};
|
|
877
|
+
for (const [name2, headerValue] of Object.entries(rawHeaders)) {
|
|
878
|
+
if (typeof headerValue === "string") headers[name2] = headerValue;
|
|
879
|
+
}
|
|
880
|
+
return {
|
|
881
|
+
kind,
|
|
882
|
+
instanceId,
|
|
883
|
+
frameName,
|
|
884
|
+
url,
|
|
885
|
+
headers,
|
|
886
|
+
config,
|
|
887
|
+
beforeKey,
|
|
888
|
+
beforeContent,
|
|
889
|
+
afterContent,
|
|
890
|
+
incognito
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
function withoutFramingRefusals(headers) {
|
|
894
|
+
const kept = [];
|
|
895
|
+
for (const header of headers) {
|
|
896
|
+
const name2 = header.name.toLowerCase();
|
|
897
|
+
if (name2 === "x-frame-options") continue;
|
|
898
|
+
if (name2 !== "content-security-policy") {
|
|
899
|
+
kept.push(header);
|
|
900
|
+
continue;
|
|
901
|
+
}
|
|
902
|
+
const policies = header.value.split(",").map(
|
|
903
|
+
(policy) => policy.split(";").filter((directive) => {
|
|
904
|
+
const directiveName = directive.trim().split(/\s+/)[0]?.toLowerCase();
|
|
905
|
+
return directiveName !== "" && directiveName !== "frame-ancestors";
|
|
906
|
+
}).join(";").trim()
|
|
907
|
+
).filter((policy) => policy !== "");
|
|
908
|
+
if (policies.length > 0) kept.push({ name: header.name, value: policies.join(", ") });
|
|
909
|
+
}
|
|
910
|
+
return kept;
|
|
911
|
+
}
|
|
912
|
+
function withFrameEmbedderHeaders(headers) {
|
|
913
|
+
const named = (name2) => headers.some((header) => header.name.toLowerCase() === name2);
|
|
914
|
+
return [
|
|
915
|
+
...headers,
|
|
916
|
+
...named("cross-origin-embedder-policy") ? [] : [{ name: "Cross-Origin-Embedder-Policy", value: "credentialless" }],
|
|
917
|
+
...named("cross-origin-resource-policy") ? [] : [{ name: "Cross-Origin-Resource-Policy", value: "cross-origin" }]
|
|
918
|
+
];
|
|
919
|
+
}
|
|
920
|
+
function firstPartyCookie(line, url) {
|
|
921
|
+
let location;
|
|
922
|
+
try {
|
|
923
|
+
location = new URL(url);
|
|
924
|
+
} catch {
|
|
925
|
+
return null;
|
|
926
|
+
}
|
|
927
|
+
const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(location.hostname);
|
|
928
|
+
if (location.protocol !== "https:" && !(location.protocol === "http:" && loopback))
|
|
929
|
+
return null;
|
|
930
|
+
const [pair = "", ...attributes] = line.split(";");
|
|
931
|
+
const separator = pair.indexOf("=");
|
|
932
|
+
if (separator <= 0) return null;
|
|
933
|
+
const cookie = {
|
|
934
|
+
name: pair.slice(0, separator).trim(),
|
|
935
|
+
value: pair.slice(separator + 1).trim(),
|
|
936
|
+
domain: location.hostname,
|
|
937
|
+
path: location.pathname.slice(0, location.pathname.lastIndexOf("/")) || "/",
|
|
938
|
+
expires: -1,
|
|
939
|
+
httpOnly: false,
|
|
940
|
+
secure: true,
|
|
941
|
+
sameSite: "None"
|
|
942
|
+
};
|
|
943
|
+
let maxAge = null;
|
|
944
|
+
for (const attribute of attributes) {
|
|
945
|
+
const equals = attribute.indexOf("=");
|
|
946
|
+
const key = (equals === -1 ? attribute : attribute.slice(0, equals)).trim().toLowerCase();
|
|
947
|
+
const value = equals === -1 ? "" : attribute.slice(equals + 1).trim();
|
|
948
|
+
if (key === "samesite" && value.toLowerCase() === "none") return null;
|
|
949
|
+
if (key === "httponly") cookie.httpOnly = true;
|
|
950
|
+
if (key === "path" && value.startsWith("/")) cookie.path = value;
|
|
951
|
+
if (key === "domain" && value) {
|
|
952
|
+
const domain = value.replace(/^\./, "").toLowerCase();
|
|
953
|
+
if (location.hostname !== domain && !location.hostname.endsWith("." + domain))
|
|
954
|
+
return null;
|
|
955
|
+
cookie.domain = "." + domain;
|
|
956
|
+
}
|
|
957
|
+
if (key === "max-age" && /^-?\d+$/.test(value)) maxAge = Number(value);
|
|
958
|
+
if (key === "expires" && maxAge === null) {
|
|
959
|
+
const time = Date.parse(value);
|
|
960
|
+
if (!Number.isNaN(time)) cookie.expires = Math.floor(time / 1e3);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
if (maxAge !== null) cookie.expires = Math.floor(Date.now() / 1e3) + maxAge;
|
|
964
|
+
return cookie;
|
|
965
|
+
}
|
|
966
|
+
function webViewBeforeContentScript(beforeKey, source) {
|
|
967
|
+
return `if ((window[Symbol.for('peach.webview')] || {}).beforeKey === ${JSON.stringify(beforeKey)}) {
|
|
968
|
+
${source}
|
|
969
|
+
}`;
|
|
970
|
+
}
|
|
971
|
+
function webViewEvaluationScripts(js) {
|
|
972
|
+
const hook = "(window[Symbol.for('peach.webview')] || { injecting: function () {} })";
|
|
973
|
+
return [`${hook}.injecting(true)`, js, `${hook}.injecting(false)`];
|
|
974
|
+
}
|
|
975
|
+
function isAppSchemeUrl(url) {
|
|
976
|
+
const browserSchemes = [
|
|
861
977
|
"http:",
|
|
862
978
|
"https:",
|
|
863
979
|
"about:",
|
|
@@ -865,57 +981,1070 @@ async function forwardPopupSchemeNavigations(context, eventName, sessionFragment
|
|
|
865
981
|
"data:",
|
|
866
982
|
"file:",
|
|
867
983
|
"javascript:"
|
|
868
|
-
]
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
984
|
+
];
|
|
985
|
+
try {
|
|
986
|
+
return !browserSchemes.includes(new URL(url).protocol);
|
|
987
|
+
} catch {
|
|
988
|
+
return false;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
function isSameDocumentRequest(requested, url) {
|
|
992
|
+
try {
|
|
993
|
+
const a = new URL(requested);
|
|
994
|
+
const b = new URL(url);
|
|
995
|
+
a.hash = "";
|
|
996
|
+
b.hash = "";
|
|
997
|
+
return a.href === b.href;
|
|
998
|
+
} catch {
|
|
999
|
+
return false;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
var webViewAutomationHelpers = {
|
|
1003
|
+
readRequest: readWebViewHostRequest,
|
|
1004
|
+
withoutFramingRefusals,
|
|
1005
|
+
withFrameEmbedderHeaders,
|
|
1006
|
+
firstPartyCookie,
|
|
1007
|
+
beforeContentScript: webViewBeforeContentScript,
|
|
1008
|
+
evaluationScripts: webViewEvaluationScripts,
|
|
1009
|
+
isAppScheme: isAppSchemeUrl,
|
|
1010
|
+
isSameDocument: isSameDocumentRequest
|
|
1011
|
+
};
|
|
1012
|
+
function webViewAutomationNames(timingName, bootstrapSource) {
|
|
1013
|
+
return {
|
|
1014
|
+
hostBinding: WEBVIEW_HOST_BINDING,
|
|
1015
|
+
instanceAttribute: WEBVIEW_INSTANCE_ATTRIBUTE,
|
|
1016
|
+
schemeNavigationEvent: WEBVIEW_SCHEME_NAVIGATION_EVENT,
|
|
1017
|
+
configTimingName: timingName,
|
|
1018
|
+
bootstrapSource: `(${bootstrapSource})(${JSON.stringify(timingName)});`
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
async function automateWebViewFrames(context, names, helpers) {
|
|
1022
|
+
await context.addInitScript({ content: names.bootstrapSource });
|
|
1023
|
+
const browser = context.browser();
|
|
1024
|
+
if (!browser) throw new Error("webview automation needs the browser behind its context");
|
|
1025
|
+
const browserSession = await browser.newBrowserCDPSession();
|
|
1026
|
+
const byFrameId = /* @__PURE__ */ new Map();
|
|
1027
|
+
const byInstance = /* @__PURE__ */ new Map();
|
|
1028
|
+
const beforeKeys = /* @__PURE__ */ new Set();
|
|
1029
|
+
const pageSessions = /* @__PURE__ */ new Map();
|
|
1030
|
+
const pageSession = (page) => {
|
|
1031
|
+
let session = pageSessions.get(page);
|
|
1032
|
+
if (!session) {
|
|
1033
|
+
session = context.newCDPSession(page);
|
|
1034
|
+
pageSessions.set(page, session);
|
|
1035
|
+
}
|
|
1036
|
+
return session;
|
|
1037
|
+
};
|
|
1038
|
+
const instanceOf = async (frame) => {
|
|
1039
|
+
const page = frame.page();
|
|
1040
|
+
if (frame.parentFrame() !== page.mainFrame()) return null;
|
|
1041
|
+
try {
|
|
1042
|
+
const element2 = await frame.frameElement();
|
|
1043
|
+
return await element2.getAttribute(names.instanceAttribute);
|
|
1044
|
+
} catch {
|
|
1045
|
+
return null;
|
|
1046
|
+
}
|
|
1047
|
+
};
|
|
1048
|
+
const reportSchemeNavigation = (page, instanceId, url) => {
|
|
1049
|
+
void page.evaluate(
|
|
1050
|
+
([eventName, detail]) => {
|
|
1051
|
+
window.dispatchEvent(new CustomEvent(eventName, { detail }));
|
|
1052
|
+
},
|
|
1053
|
+
[names.schemeNavigationEvent, { instanceId, url }]
|
|
1054
|
+
).catch(() => {
|
|
873
1055
|
});
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
1056
|
+
};
|
|
1057
|
+
context.on("request", (request) => {
|
|
1058
|
+
if (!request.isNavigationRequest() || request.redirectedFrom()) return;
|
|
1059
|
+
if (!helpers.isAppScheme(request.url())) return;
|
|
1060
|
+
const frame = request.frame();
|
|
1061
|
+
void instanceOf(frame).then((instanceId) => {
|
|
1062
|
+
if (instanceId !== null)
|
|
1063
|
+
reportSchemeNavigation(frame.page(), instanceId, request.url());
|
|
1064
|
+
});
|
|
1065
|
+
});
|
|
1066
|
+
const storeFirstPartyCookies = async (lines, url) => {
|
|
1067
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
1068
|
+
for (const line of lines) {
|
|
1069
|
+
const cookie = helpers.firstPartyCookie(line, url);
|
|
1070
|
+
if (!cookie) continue;
|
|
1071
|
+
if (cookie.expires !== -1 && cookie.expires <= now) {
|
|
1072
|
+
await context.clearCookies({
|
|
1073
|
+
name: cookie.name,
|
|
1074
|
+
domain: cookie.domain,
|
|
1075
|
+
path: cookie.path
|
|
1076
|
+
});
|
|
1077
|
+
} else {
|
|
1078
|
+
await context.addCookies([cookie]);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
context.on("response", (response) => {
|
|
1083
|
+
const request = response.request();
|
|
1084
|
+
const frame = request.frame();
|
|
1085
|
+
if (request.isNavigationRequest()) return;
|
|
1086
|
+
if (frame.parentFrame() !== frame.page().mainFrame()) return;
|
|
1087
|
+
void (async () => {
|
|
1088
|
+
const lines = await response.headerValues("set-cookie");
|
|
1089
|
+
if (lines.length === 0) return;
|
|
1090
|
+
const instanceId = await instanceOf(frame);
|
|
1091
|
+
const bound = instanceId === null ? void 0 : byInstance.get(instanceId);
|
|
1092
|
+
if (!bound || bound.incognito) return;
|
|
1093
|
+
const fetchSite = await request.headerValue("sec-fetch-site");
|
|
1094
|
+
if (fetchSite !== "same-origin" && fetchSite !== "same-site") return;
|
|
1095
|
+
await storeFirstPartyCookies(lines, response.url());
|
|
1096
|
+
})().catch(() => {
|
|
1097
|
+
});
|
|
1098
|
+
});
|
|
1099
|
+
const watchDocumentCookies = async (session) => {
|
|
1100
|
+
const documents = /* @__PURE__ */ new Map();
|
|
1101
|
+
session.on(
|
|
1102
|
+
"Network.requestWillBeSent",
|
|
1103
|
+
(event) => {
|
|
1104
|
+
if (event.type === "Document" && event.frameId)
|
|
1105
|
+
documents.set(event.requestId, {
|
|
1106
|
+
frameId: event.frameId,
|
|
1107
|
+
url: event.request.url
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
);
|
|
1111
|
+
session.on(
|
|
1112
|
+
"Network.responseReceivedExtraInfo",
|
|
1113
|
+
(event) => {
|
|
1114
|
+
const load = documents.get(event.requestId);
|
|
1115
|
+
if (!load) return;
|
|
1116
|
+
const bound = byFrameId.get(load.frameId);
|
|
1117
|
+
if (!bound || bound.incognito) return;
|
|
1118
|
+
const refused = new Set(
|
|
1119
|
+
(event.blockedCookies ?? []).filter(
|
|
1120
|
+
(blocked) => blocked.blockedReasons.some((reason) => !reason.includes("SameSite"))
|
|
1121
|
+
).map((blocked) => blocked.cookieLine)
|
|
879
1122
|
);
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
void opener.then(pending.resolve, () => pending.resolve(null));
|
|
884
|
-
}
|
|
885
|
-
} catch {
|
|
1123
|
+
const lines = Object.entries(event.headers).filter(([name2]) => name2.toLowerCase() === "set-cookie").flatMap(([, value]) => value.split("\n")).filter((line) => !refused.has(line));
|
|
1124
|
+
void storeFirstPartyCookies(lines, load.url).catch(() => {
|
|
1125
|
+
});
|
|
886
1126
|
}
|
|
887
|
-
};
|
|
888
|
-
recordSession();
|
|
889
|
-
popup.on("framenavigated", recordSession);
|
|
890
|
-
const forward = (detail) => opener.then(
|
|
891
|
-
(page) => page?.evaluate(
|
|
892
|
-
([name2, detail2]) => !window.dispatchEvent(new CustomEvent(name2, { detail: detail2, cancelable: true })),
|
|
893
|
-
[eventName, detail]
|
|
894
|
-
)
|
|
895
1127
|
);
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
1128
|
+
session.on("Network.loadingFinished", (event) => {
|
|
1129
|
+
documents.delete(event.requestId);
|
|
1130
|
+
});
|
|
1131
|
+
session.on("Network.loadingFailed", (event) => {
|
|
1132
|
+
documents.delete(event.requestId);
|
|
1133
|
+
});
|
|
1134
|
+
await session.send("Network.enable");
|
|
1135
|
+
};
|
|
1136
|
+
const watchedPages = /* @__PURE__ */ new Set();
|
|
1137
|
+
const followFrameProcesses = async (page) => {
|
|
1138
|
+
if (watchedPages.has(page)) return;
|
|
1139
|
+
watchedPages.add(page);
|
|
1140
|
+
await watchDocumentCookies(await pageSession(page));
|
|
1141
|
+
page.on("framenavigated", (frame) => {
|
|
1142
|
+
if (frame.parentFrame() !== page.mainFrame()) return;
|
|
1143
|
+
void (async () => {
|
|
1144
|
+
const instanceId = await instanceOf(frame);
|
|
1145
|
+
const bound = instanceId === null ? void 0 : byInstance.get(instanceId);
|
|
1146
|
+
if (!bound || bound.frameSession) return;
|
|
1147
|
+
const session = await context.newCDPSession(frame).catch(() => null);
|
|
1148
|
+
if (!session) return;
|
|
1149
|
+
bound.frameSession = session;
|
|
1150
|
+
await watchDocumentCookies(session);
|
|
1151
|
+
})().catch(() => {
|
|
901
1152
|
});
|
|
902
1153
|
});
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
1154
|
+
};
|
|
1155
|
+
const isPageFrame = async (frameId) => {
|
|
1156
|
+
const { targetInfos } = await browserSession.send("Target.getTargets");
|
|
1157
|
+
return targetInfos.some(
|
|
1158
|
+
(target) => target.type === "page" && target.targetId === frameId
|
|
1159
|
+
);
|
|
1160
|
+
};
|
|
1161
|
+
const fulfill = (requestId, event, headers) => browserSession.send("Fetch.getResponseBody", { requestId }).then((body) => {
|
|
1162
|
+
let encoded = body.body;
|
|
1163
|
+
if (!body.base64Encoded) {
|
|
1164
|
+
const bytes = new TextEncoder().encode(body.body);
|
|
1165
|
+
let binary = "";
|
|
1166
|
+
for (let index = 0; index < bytes.length; index += 32768) {
|
|
1167
|
+
binary += String.fromCharCode(...bytes.subarray(index, index + 32768));
|
|
1168
|
+
}
|
|
1169
|
+
encoded = btoa(binary);
|
|
1170
|
+
}
|
|
1171
|
+
return browserSession.send("Fetch.fulfillRequest", {
|
|
1172
|
+
requestId,
|
|
1173
|
+
responseCode: event.responseStatusCode,
|
|
1174
|
+
responsePhrase: event.responseStatusText || void 0,
|
|
1175
|
+
responseHeaders: headers.filter(
|
|
1176
|
+
(header) => !/^content-(encoding|length)$/i.test(header.name)
|
|
1177
|
+
),
|
|
1178
|
+
body: encoded
|
|
1179
|
+
});
|
|
1180
|
+
}).catch(() => browserSession.send("Fetch.continueRequest", { requestId })).catch(() => {
|
|
1181
|
+
});
|
|
1182
|
+
await browserSession.send("Fetch.enable", {
|
|
1183
|
+
patterns: [{ urlPattern: "*", resourceType: "Document", requestStage: "Request" }]
|
|
1184
|
+
});
|
|
1185
|
+
browserSession.on("Fetch.requestPaused", (event) => {
|
|
1186
|
+
const requestId = event.requestId;
|
|
1187
|
+
const frameId = typeof event.frameId === "string" ? event.frameId : "";
|
|
1188
|
+
const bound = byFrameId.get(frameId);
|
|
1189
|
+
const settle = (method, params) => browserSession.send(method, { requestId, ...params }).catch(() => {
|
|
1190
|
+
});
|
|
1191
|
+
const requestStage = event.responseStatusCode === void 0 && event.responseErrorReason === void 0;
|
|
1192
|
+
if (!bound) {
|
|
1193
|
+
if (requestStage) {
|
|
1194
|
+
void isPageFrame(frameId).catch(() => true).then(
|
|
1195
|
+
(pageFrame) => settle("Fetch.continueRequest", { interceptResponse: !pageFrame })
|
|
1196
|
+
);
|
|
910
1197
|
return;
|
|
911
1198
|
}
|
|
912
|
-
|
|
913
|
-
|
|
1199
|
+
const received2 = event.responseHeaders ?? [];
|
|
1200
|
+
const status2 = event.responseStatusCode;
|
|
1201
|
+
const statesPolicy = received2.some(
|
|
1202
|
+
(header) => header.name.toLowerCase() === "cross-origin-embedder-policy"
|
|
1203
|
+
);
|
|
1204
|
+
if (event.responseErrorReason !== void 0 || statesPolicy || status2 >= 300 && status2 < 400) {
|
|
1205
|
+
void settle("Fetch.continueRequest", {});
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
void fulfill(requestId, event, helpers.withFrameEmbedderHeaders(received2));
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
if (requestStage) {
|
|
1212
|
+
const load = bound.load;
|
|
1213
|
+
if (load && helpers.isSameDocument(event.request.url, load.url)) {
|
|
1214
|
+
bound.load = null;
|
|
1215
|
+
if (Object.keys(load.headers).length > 0) {
|
|
1216
|
+
const headers = Object.entries({
|
|
1217
|
+
...event.request.headers,
|
|
1218
|
+
...load.headers
|
|
1219
|
+
}).map(([name2, value]) => ({ name: name2, value: String(value) }));
|
|
1220
|
+
void settle("Fetch.continueRequest", { headers, interceptResponse: true });
|
|
1221
|
+
return;
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
void settle("Fetch.continueRequest", { interceptResponse: true });
|
|
1225
|
+
return;
|
|
1226
|
+
}
|
|
1227
|
+
if (event.responseErrorReason !== void 0) {
|
|
1228
|
+
void settle("Fetch.continueRequest", {});
|
|
1229
|
+
return;
|
|
1230
|
+
}
|
|
1231
|
+
const status = event.responseStatusCode;
|
|
1232
|
+
const received = event.responseHeaders ?? [];
|
|
1233
|
+
if (status >= 300 && status < 400) {
|
|
1234
|
+
const location = received.find((header) => header.name.toLowerCase() === "location");
|
|
1235
|
+
if (location) {
|
|
1236
|
+
let target = "";
|
|
1237
|
+
try {
|
|
1238
|
+
target = new URL(location.value, event.request.url).href;
|
|
1239
|
+
} catch {
|
|
1240
|
+
}
|
|
1241
|
+
if (helpers.isAppScheme(target))
|
|
1242
|
+
reportSchemeNavigation(bound.page, bound.instanceId, target);
|
|
1243
|
+
}
|
|
1244
|
+
void settle("Fetch.continueRequest", {});
|
|
1245
|
+
return;
|
|
1246
|
+
}
|
|
1247
|
+
void fulfill(requestId, event, [
|
|
1248
|
+
...helpers.withFrameEmbedderHeaders(helpers.withoutFramingRefusals(received)),
|
|
1249
|
+
{
|
|
1250
|
+
name: "Server-Timing",
|
|
1251
|
+
value: `${names.configTimingName};desc="${encodeURIComponent(bound.config)}"`
|
|
1252
|
+
}
|
|
1253
|
+
]);
|
|
1254
|
+
});
|
|
1255
|
+
const evaluateIn = async (bound, scripts) => {
|
|
1256
|
+
let frame = null;
|
|
1257
|
+
for (const candidate of bound.page.frames()) {
|
|
1258
|
+
if (await instanceOf(candidate) === bound.instanceId) frame = candidate;
|
|
1259
|
+
}
|
|
1260
|
+
if (!frame) return;
|
|
1261
|
+
let session = null;
|
|
1262
|
+
let contextId;
|
|
1263
|
+
try {
|
|
1264
|
+
session = await context.newCDPSession(frame);
|
|
1265
|
+
} catch {
|
|
1266
|
+
session = await pageSession(bound.page);
|
|
1267
|
+
const contexts = [];
|
|
1268
|
+
const collect = (event) => {
|
|
1269
|
+
contexts.push(event.context);
|
|
1270
|
+
};
|
|
1271
|
+
session.on("Runtime.executionContextCreated", collect);
|
|
1272
|
+
await session.send("Runtime.enable");
|
|
1273
|
+
await session.send("Runtime.disable");
|
|
1274
|
+
session.off("Runtime.executionContextCreated", collect);
|
|
1275
|
+
contextId = contexts.find(
|
|
1276
|
+
(entry) => entry.auxData?.frameId === bound.frameId && entry.auxData.isDefault
|
|
1277
|
+
)?.id;
|
|
1278
|
+
if (contextId === void 0) return;
|
|
1279
|
+
}
|
|
1280
|
+
try {
|
|
1281
|
+
for (const expression of scripts) {
|
|
1282
|
+
await session.send("Runtime.evaluate", { expression, contextId });
|
|
1283
|
+
}
|
|
1284
|
+
} finally {
|
|
1285
|
+
if (contextId === void 0) await session.detach().catch(() => {
|
|
914
1286
|
});
|
|
1287
|
+
}
|
|
1288
|
+
};
|
|
1289
|
+
await context.exposeBinding(names.hostBinding, async (source, value) => {
|
|
1290
|
+
if (source.frame !== source.page.mainFrame()) {
|
|
1291
|
+
if (Reflect.get(Object(value), "kind") !== "documentEnd") return;
|
|
1292
|
+
const instanceId = await instanceOf(source.frame);
|
|
1293
|
+
const bound2 = instanceId === null ? void 0 : byInstance.get(instanceId);
|
|
1294
|
+
if (!bound2 || !bound2.afterContent) return;
|
|
1295
|
+
const scripts = helpers.evaluationScripts(bound2.afterContent);
|
|
1296
|
+
bound2.evaluations = bound2.evaluations.then(() => evaluateIn(bound2, scripts)).catch(() => {
|
|
1297
|
+
});
|
|
1298
|
+
await bound2.evaluations;
|
|
1299
|
+
return;
|
|
1300
|
+
}
|
|
1301
|
+
const request = helpers.readRequest(value);
|
|
1302
|
+
if (!request) return;
|
|
1303
|
+
if (request.kind === "detach") {
|
|
1304
|
+
const bound2 = byInstance.get(request.instanceId);
|
|
1305
|
+
if (bound2) {
|
|
1306
|
+
byFrameId.delete(bound2.frameId);
|
|
1307
|
+
await bound2.frameSession?.detach().catch(() => {
|
|
1308
|
+
});
|
|
1309
|
+
}
|
|
1310
|
+
byInstance.delete(request.instanceId);
|
|
1311
|
+
return;
|
|
1312
|
+
}
|
|
1313
|
+
if (request.kind === "tap") {
|
|
1314
|
+
await source.page.mouse.click(request.x, request.y);
|
|
1315
|
+
return;
|
|
1316
|
+
}
|
|
1317
|
+
if (request.kind === "evaluate") {
|
|
1318
|
+
const bound2 = byInstance.get(request.instanceId);
|
|
1319
|
+
if (!bound2) return;
|
|
1320
|
+
const scripts = helpers.evaluationScripts(request.js);
|
|
1321
|
+
bound2.evaluations = bound2.evaluations.then(() => evaluateIn(bound2, scripts)).catch(() => {
|
|
1322
|
+
});
|
|
1323
|
+
await bound2.evaluations;
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
const session = await pageSession(source.page);
|
|
1327
|
+
const found = await session.send("Runtime.evaluate", {
|
|
1328
|
+
expression: `document.querySelector('iframe[${names.instanceAttribute}="${request.instanceId.replace(/[^\w-]/g, "")}"]')`
|
|
915
1329
|
});
|
|
1330
|
+
const objectId = found.result?.objectId;
|
|
1331
|
+
if (!objectId) return;
|
|
1332
|
+
const described = await session.send("DOM.describeNode", { objectId });
|
|
1333
|
+
await session.send("Runtime.releaseObject", { objectId });
|
|
1334
|
+
const frameId = described.node?.frameId;
|
|
1335
|
+
if (!frameId) return;
|
|
1336
|
+
const previous = byInstance.get(request.instanceId);
|
|
1337
|
+
if (previous) {
|
|
1338
|
+
byFrameId.delete(previous.frameId);
|
|
1339
|
+
await previous.frameSession?.detach().catch(() => {
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
const bound = {
|
|
1343
|
+
instanceId: request.instanceId,
|
|
1344
|
+
page: source.page,
|
|
1345
|
+
frameId,
|
|
1346
|
+
config: request.config,
|
|
1347
|
+
afterContent: request.afterContent,
|
|
1348
|
+
incognito: request.incognito,
|
|
1349
|
+
load: { url: request.url, headers: request.headers },
|
|
1350
|
+
evaluations: Promise.resolve(),
|
|
1351
|
+
frameSession: null
|
|
1352
|
+
};
|
|
1353
|
+
byFrameId.set(frameId, bound);
|
|
1354
|
+
byInstance.set(request.instanceId, bound);
|
|
1355
|
+
await followFrameProcesses(source.page);
|
|
1356
|
+
if (request.beforeContent && !beforeKeys.has(request.beforeKey)) {
|
|
1357
|
+
beforeKeys.add(request.beforeKey);
|
|
1358
|
+
await context.addInitScript({
|
|
1359
|
+
content: helpers.beforeContentScript(request.beforeKey, request.beforeContent)
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
916
1362
|
});
|
|
917
1363
|
}
|
|
918
1364
|
|
|
1365
|
+
// ../peach-engine/src/components/native-ui/webview-frame-bridge.ts
|
|
1366
|
+
var WEBVIEW_FRAME_CONFIG_ATTRIBUTE = "data-peach-webview-config";
|
|
1367
|
+
var WEBVIEW_FRAME_HOOK = "peach.webview";
|
|
1368
|
+
var WEBVIEW_FRAME_BRIDGE_SOURCE = `function (config) {
|
|
1369
|
+
// an html source is rendered in a srcdoc frame, so location.href here is
|
|
1370
|
+
// about:srcdoc while the same document on device is really loaded at
|
|
1371
|
+
// source.baseUrl. everything the app can observe (nativeEvent.url, the
|
|
1372
|
+
// url handed to onShouldStartLoadWithRequest, and therefore upstream's
|
|
1373
|
+
// originWhitelist and Linking handling) has to speak that url, so map the
|
|
1374
|
+
// frame's own search and hash onto it.
|
|
1375
|
+
var documentUrl = config.documentUrl;
|
|
1376
|
+
var webKit = config.webKit || null;
|
|
1377
|
+
function nativeValue(value, seen) {
|
|
1378
|
+
if (value === null) return { type: 'null' };
|
|
1379
|
+
if (typeof value === 'string' || typeof value === 'boolean') return { type: typeof value, value: value };
|
|
1380
|
+
if (typeof value === 'number') {
|
|
1381
|
+
if (Number.isNaN(value)) return { type: 'number', value: 'nan' };
|
|
1382
|
+
if (value === Infinity) return { type: 'number', value: 'infinity' };
|
|
1383
|
+
if (value === -Infinity) return { type: 'number', value: 'negativeInfinity' };
|
|
1384
|
+
if (Object.is(value, -0)) return { type: 'number', value: 'negativeZero' };
|
|
1385
|
+
return { type: 'number', value: value };
|
|
1386
|
+
}
|
|
1387
|
+
if (value instanceof Date && Number.isFinite(value.getTime())) return { type: 'date', value: value.getTime() };
|
|
1388
|
+
if (typeof value !== 'object' || value instanceof Node || value instanceof Promise) throw new Error('unsupported JavaScript result');
|
|
1389
|
+
if (seen.indexOf(value) !== -1) throw new Error('cyclic JavaScript result');
|
|
1390
|
+
seen.push(value);
|
|
1391
|
+
var converted;
|
|
1392
|
+
if (Array.isArray(value)) converted = { type: 'array', value: value.map(function(item) { return nativeValue(item, seen); }) };
|
|
1393
|
+
else {
|
|
1394
|
+
var fields = Object.create(null);
|
|
1395
|
+
Object.keys(value).forEach(function(key) { fields[key] = nativeValue(value[key], seen); });
|
|
1396
|
+
converted = { type: 'object', value: fields };
|
|
1397
|
+
}
|
|
1398
|
+
seen.pop();
|
|
1399
|
+
return converted;
|
|
1400
|
+
}
|
|
1401
|
+
function setMessageHandlers(names) {
|
|
1402
|
+
Object.keys(window.webkit.messageHandlers).forEach(function(name) { if (names.indexOf(name) === -1) delete window.webkit.messageHandlers[name]; });
|
|
1403
|
+
names.forEach(function(name) {
|
|
1404
|
+
if (Object.hasOwn(window.webkit.messageHandlers, name)) return;
|
|
1405
|
+
window.webkit.messageHandlers[name] = { postMessage: function(body) {
|
|
1406
|
+
window.parent.postMessage({ __sootsimWebViewKind: 'webKitMessage', name: name, body: nativeValue(body, []) }, '*');
|
|
1407
|
+
} };
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
if (webKit) {
|
|
1411
|
+
var systemFont = document.createElement('style');
|
|
1412
|
+
// srcdoc's base belongs to the app page; the system font belongs to the host.
|
|
1413
|
+
systemFont.textContent = config.systemFontStyle;
|
|
1414
|
+
document.head.appendChild(systemFont);
|
|
1415
|
+
Object.defineProperty(window, 'devicePixelRatio', { configurable: true, get: function() { return config.deviceScale; } });
|
|
1416
|
+
window.parent.postMessage({ __sootsimWebViewKind: 'webKitCommit' }, '*');
|
|
1417
|
+
window.webkit = window.webkit || {};
|
|
1418
|
+
window.webkit.messageHandlers = Object.create(null);
|
|
1419
|
+
setMessageHandlers(webKit.messageHandlers);
|
|
1420
|
+
}
|
|
1421
|
+
var userScripts = (webKit ? webKit.userScripts : []).slice();
|
|
1422
|
+
userScripts.filter(function(script) { return script.time === 0; }).forEach(function(script) { (0,eval)(script.source); });
|
|
1423
|
+
document.addEventListener('DOMContentLoaded', function() {
|
|
1424
|
+
userScripts.filter(function(script) { return script.time === 1; }).forEach(function(script) { (0,eval)(script.source); });
|
|
1425
|
+
}, { once: true });
|
|
1426
|
+
function frameUrl() {
|
|
1427
|
+
if (location.protocol !== 'about:') return String(location.href);
|
|
1428
|
+
try {
|
|
1429
|
+
return String(new URL(location.search + location.hash, documentUrl));
|
|
1430
|
+
} catch (_) {
|
|
1431
|
+
return documentUrl;
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
window.ReactNativeWebView = window.ReactNativeWebView || {
|
|
1435
|
+
postMessage: function (data) {
|
|
1436
|
+
window.parent.postMessage({
|
|
1437
|
+
__sootsimWebViewKind: 'reactNativeWebViewMessage',
|
|
1438
|
+
data: String(data),
|
|
1439
|
+
url: frameUrl(),
|
|
1440
|
+
loading: document.readyState !== 'complete',
|
|
1441
|
+
title: String(document.title || '')
|
|
1442
|
+
}, '*')
|
|
1443
|
+
}
|
|
1444
|
+
};
|
|
1445
|
+
if (typeof config.injectedObjectJson === 'string') {
|
|
1446
|
+
var injectedObjectJson = config.injectedObjectJson;
|
|
1447
|
+
window.ReactNativeWebView.injectedObjectJson = function () {
|
|
1448
|
+
return injectedObjectJson;
|
|
1449
|
+
};
|
|
1450
|
+
}
|
|
1451
|
+
// the page is top-level in a WKWebView, so a cookie it sets from script is
|
|
1452
|
+
// first-party there; under the sim page it is cross-site, where only
|
|
1453
|
+
// SameSite=None sticks. a secure context can state that; an insecure one
|
|
1454
|
+
// keeps the browser's refusal.
|
|
1455
|
+
var crossOriginToSim = true;
|
|
1456
|
+
try {
|
|
1457
|
+
crossOriginToSim = window.top.location.href === undefined;
|
|
1458
|
+
} catch (_) {}
|
|
1459
|
+
var cookieProperty = Object.getOwnPropertyDescriptor(Document.prototype, 'cookie');
|
|
1460
|
+
if (crossOriginToSim && window.isSecureContext && cookieProperty) {
|
|
1461
|
+
Object.defineProperty(Document.prototype, 'cookie', {
|
|
1462
|
+
configurable: true,
|
|
1463
|
+
enumerable: cookieProperty.enumerable,
|
|
1464
|
+
get: cookieProperty.get,
|
|
1465
|
+
set: function (value) {
|
|
1466
|
+
var line = String(value);
|
|
1467
|
+
if (!/;\\s*samesite\\s*=\\s*none\\b/i.test(line)) {
|
|
1468
|
+
line = line.replace(/;\\s*samesite\\s*=[^;]*/gi, '') + '; SameSite=None; Secure';
|
|
1469
|
+
}
|
|
1470
|
+
cookieProperty.set.call(this, line);
|
|
1471
|
+
}
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
var evaluatingInjectedScript = false;
|
|
1475
|
+
var hook = {
|
|
1476
|
+
beforeKey: config.beforeKey,
|
|
1477
|
+
injecting: function (active) {
|
|
1478
|
+
evaluatingInjectedScript = active === true;
|
|
1479
|
+
},
|
|
1480
|
+
// a browser host's pending document-end injectedJavaScript, if any
|
|
1481
|
+
documentEnd: null
|
|
1482
|
+
};
|
|
1483
|
+
Object.defineProperty(window, Symbol.for(${JSON.stringify(WEBVIEW_FRAME_HOOK)}), {
|
|
1484
|
+
value: hook
|
|
1485
|
+
});
|
|
1486
|
+
if (config.hasOpenWindowHandler) {
|
|
1487
|
+
window.open = function (url) {
|
|
1488
|
+
var targetUrl = String(url || 'about:blank');
|
|
1489
|
+
try { targetUrl = String(new URL(targetUrl, window.location.href)); } catch (_) {}
|
|
1490
|
+
window.parent.postMessage({
|
|
1491
|
+
__sootsimWebViewKind: 'webViewOpenWindow',
|
|
1492
|
+
targetUrl: targetUrl
|
|
1493
|
+
}, '*');
|
|
1494
|
+
return null;
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
// WKWebView runs every navigation past the policy delegate first, and
|
|
1498
|
+
// upstream builds the app's onShouldStartLoadWithRequest body from it. a
|
|
1499
|
+
// same-document move (a fragment link, a location.hash write, a
|
|
1500
|
+
// pushState) is already applied by the time WebKit reports it, and
|
|
1501
|
+
// cancelling one does not undo it; measured on an iOS 26 simulator, a
|
|
1502
|
+
// denied fragment link still left the document at that fragment. a
|
|
1503
|
+
// cross-document load is genuinely cancellable, so only that one waits
|
|
1504
|
+
// for the decision here.
|
|
1505
|
+
var navigationRequestSequence = 0;
|
|
1506
|
+
var pendingCrossDocumentNavigation = Object.create(null);
|
|
1507
|
+
var pendingTraversals = Object.create(null);
|
|
1508
|
+
var reportedSameDocumentUrl = null;
|
|
1509
|
+
function reportNavigationState() {
|
|
1510
|
+
window.parent.postMessage({
|
|
1511
|
+
__sootsimWebViewKind: 'webViewNavigationState',
|
|
1512
|
+
url: frameUrl(),
|
|
1513
|
+
title: String(document.title || '')
|
|
1514
|
+
}, '*');
|
|
1515
|
+
}
|
|
1516
|
+
function requestSameDocumentNavigation(navigationType) {
|
|
1517
|
+
var url = frameUrl();
|
|
1518
|
+
if (url === reportedSameDocumentUrl) return;
|
|
1519
|
+
reportedSameDocumentUrl = url;
|
|
1520
|
+
reportNavigationState();
|
|
1521
|
+
window.parent.postMessage({
|
|
1522
|
+
__sootsimWebViewKind: 'webViewShouldStartLoad',
|
|
1523
|
+
requestId: ++navigationRequestSequence,
|
|
1524
|
+
url: url,
|
|
1525
|
+
navigationType: navigationType,
|
|
1526
|
+
sameDocument: true
|
|
1527
|
+
}, '*');
|
|
1528
|
+
}
|
|
1529
|
+
var nativePushState = history.pushState.bind(history);
|
|
1530
|
+
var nativeReplaceState = history.replaceState.bind(history);
|
|
1531
|
+
history.pushState = function (state, unused, url) {
|
|
1532
|
+
nativePushState(state, unused, url);
|
|
1533
|
+
requestSameDocumentNavigation('other');
|
|
1534
|
+
};
|
|
1535
|
+
history.replaceState = function (state, unused, url) {
|
|
1536
|
+
nativeReplaceState(state, unused, url);
|
|
1537
|
+
requestSameDocumentNavigation('other');
|
|
1538
|
+
};
|
|
1539
|
+
window.addEventListener('hashchange', function () {
|
|
1540
|
+
requestSameDocumentNavigation('other');
|
|
1541
|
+
});
|
|
1542
|
+
document.addEventListener('DOMContentLoaded', reportNavigationState);
|
|
1543
|
+
// bubble phase, so a page handler that cancels its own link has already
|
|
1544
|
+
// run, the way WKWebView only consults the policy delegate for a
|
|
1545
|
+
// navigation the page actually let start.
|
|
1546
|
+
var pendingFormSubmissions = Object.create(null);
|
|
1547
|
+
// a navigation aimed at a window that does not exist has no target
|
|
1548
|
+
// frame. with an onOpenWindow handler upstream cancels it and reports
|
|
1549
|
+
// its url there instead (RNCWebViewImpl.m:1351-1363); without one the
|
|
1550
|
+
// browser default stands.
|
|
1551
|
+
var hasOpenWindowHandler = config.hasOpenWindowHandler;
|
|
1552
|
+
// the webview's document is its own top frame, so _parent, _top and its
|
|
1553
|
+
// own window name all navigate it in place. keywords are case-insensitive.
|
|
1554
|
+
function targetsThisDocument(target) {
|
|
1555
|
+
var keyword = target.toLowerCase();
|
|
1556
|
+
return !target || keyword === '_self' || keyword === '_parent' || keyword === '_top' ||
|
|
1557
|
+
target === window.name;
|
|
1558
|
+
}
|
|
1559
|
+
function opensNewWindow(target) {
|
|
1560
|
+
if (target.toLowerCase() === '_blank') return true;
|
|
1561
|
+
if (targetsThisDocument(target)) return false;
|
|
1562
|
+
return !Array.prototype.some.call(document.querySelectorAll('iframe, frame'), function (frame) {
|
|
1563
|
+
return frame.name === target;
|
|
1564
|
+
});
|
|
1565
|
+
}
|
|
1566
|
+
function requestOpenWindow(event, url) {
|
|
1567
|
+
event.preventDefault();
|
|
1568
|
+
window.parent.postMessage({
|
|
1569
|
+
__sootsimWebViewKind: 'webViewOpenWindow',
|
|
1570
|
+
targetUrl: String(url)
|
|
1571
|
+
}, '*');
|
|
1572
|
+
}
|
|
1573
|
+
// an image button submits the point it was activated at, relative to
|
|
1574
|
+
// the image; a keyboard activation submits 0,0.
|
|
1575
|
+
var imageSubmitPoints = new WeakMap();
|
|
1576
|
+
document.addEventListener('click', function (event) {
|
|
1577
|
+
var element = event.target;
|
|
1578
|
+
if (element && element.tagName === 'INPUT' && element.type === 'image') {
|
|
1579
|
+
imageSubmitPoints.set(element, [event.offsetX, event.offsetY]);
|
|
1580
|
+
}
|
|
1581
|
+
}, true);
|
|
1582
|
+
document.addEventListener('click', function (event) {
|
|
1583
|
+
if (event.defaultPrevented) return;
|
|
1584
|
+
if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
|
1585
|
+
var element = event.target;
|
|
1586
|
+
var anchor = element && element.closest ? element.closest('a[href]') : null;
|
|
1587
|
+
if (!anchor) return;
|
|
1588
|
+
var anchorTarget = String(anchor.target || '');
|
|
1589
|
+
// a targeted link is a new-window request, which upstream answers
|
|
1590
|
+
// through onOpenWindow rather than the navigation policy handler.
|
|
1591
|
+
if (hasOpenWindowHandler && opensNewWindow(anchorTarget)) {
|
|
1592
|
+
requestOpenWindow(event, anchor.href);
|
|
1593
|
+
return;
|
|
1594
|
+
}
|
|
1595
|
+
if (!targetsThisDocument(anchorTarget)) return;
|
|
1596
|
+
var rawHref = anchor.getAttribute('href');
|
|
1597
|
+
var base;
|
|
1598
|
+
var target;
|
|
1599
|
+
try {
|
|
1600
|
+
base = new URL(frameUrl());
|
|
1601
|
+
target = new URL(rawHref, base);
|
|
1602
|
+
} catch (_) {
|
|
1603
|
+
return;
|
|
1604
|
+
}
|
|
1605
|
+
if (target.origin === base.origin &&
|
|
1606
|
+
target.pathname === base.pathname &&
|
|
1607
|
+
target.search === base.search) {
|
|
1608
|
+
// the document carries a <base href> for source.baseUrl, so the
|
|
1609
|
+
// browser would resolve this link to that absolute url and leave the
|
|
1610
|
+
// srcdoc container entirely. move the container's own fragment
|
|
1611
|
+
// instead, which is the same-document navigation WebKit makes on
|
|
1612
|
+
// device, then report it the way WebKit reports one it has already
|
|
1613
|
+
// applied. setting reportedSameDocumentUrl first keeps the
|
|
1614
|
+
// hashchange this triggers from reporting the move a second time.
|
|
1615
|
+
event.preventDefault();
|
|
1616
|
+
reportedSameDocumentUrl = String(target);
|
|
1617
|
+
if (location.hash !== target.hash) location.hash = target.hash;
|
|
1618
|
+
reportNavigationState();
|
|
1619
|
+
window.parent.postMessage({
|
|
1620
|
+
__sootsimWebViewKind: 'webViewShouldStartLoad',
|
|
1621
|
+
requestId: ++navigationRequestSequence,
|
|
1622
|
+
url: String(target),
|
|
1623
|
+
navigationType: 'click',
|
|
1624
|
+
sameDocument: true
|
|
1625
|
+
}, '*');
|
|
1626
|
+
return;
|
|
1627
|
+
}
|
|
1628
|
+
event.preventDefault();
|
|
1629
|
+
var requestId = ++navigationRequestSequence;
|
|
1630
|
+
pendingCrossDocumentNavigation[requestId] = String(target);
|
|
1631
|
+
window.parent.postMessage({
|
|
1632
|
+
__sootsimWebViewKind: 'webViewShouldStartLoad',
|
|
1633
|
+
requestId: requestId,
|
|
1634
|
+
url: String(target),
|
|
1635
|
+
navigationType: 'click',
|
|
1636
|
+
sameDocument: false
|
|
1637
|
+
}, '*');
|
|
1638
|
+
});
|
|
1639
|
+
// a form submit is a formsubmit navigation on iOS
|
|
1640
|
+
// (RNCWebViewImpl.m:1338), asked through the same policy delegate. the
|
|
1641
|
+
// bridge holds the submit the way the click path holds a cross-document
|
|
1642
|
+
// load, and only the verdict travels: allow performs the native submit
|
|
1643
|
+
// in place, keeping the method and body a url reload would drop. bubble
|
|
1644
|
+
// phase like clicks, so a form-level page handler that cancels its own
|
|
1645
|
+
// submit is already visible; a document-level page handler registered
|
|
1646
|
+
// after this bridge still runs after the hold, which webkit would have
|
|
1647
|
+
// let cancel the navigation. a targeted submit is a new-window request,
|
|
1648
|
+
// answered through onOpenWindow rather than the policy handler.
|
|
1649
|
+
function holdFormSubmission(event) {
|
|
1650
|
+
if (event.defaultPrevented) return;
|
|
1651
|
+
var form = event.target;
|
|
1652
|
+
if (!form || form.tagName !== 'FORM') return;
|
|
1653
|
+
// a control named like a form property (action, method, target,
|
|
1654
|
+
// submit) shadows it on the element, so the form's own values come
|
|
1655
|
+
// from the prototype.
|
|
1656
|
+
var formProperty = function (name) {
|
|
1657
|
+
return Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, name).get.call(form);
|
|
1658
|
+
};
|
|
1659
|
+
// the request is webkit's FormSubmission: the submitter's formaction,
|
|
1660
|
+
// formmethod, formenctype and formtarget win, and a get submit
|
|
1661
|
+
// replaces the action url's query with the urlencoded form data,
|
|
1662
|
+
// keeping its fragment.
|
|
1663
|
+
var submitter = event.submitter || null;
|
|
1664
|
+
var submitterOverride = function (attribute, property, name) {
|
|
1665
|
+
return submitter && submitter.hasAttribute(attribute) ? submitter[property] : formProperty(name);
|
|
1666
|
+
};
|
|
1667
|
+
var formTarget = String(submitterOverride('formtarget', 'formTarget', 'target') || '');
|
|
1668
|
+
var newWindowRequest = hasOpenWindowHandler && opensNewWindow(formTarget);
|
|
1669
|
+
if (!newWindowRequest && !targetsThisDocument(formTarget)) return;
|
|
1670
|
+
var actionAttr = submitterOverride('formaction', 'formAction', 'action');
|
|
1671
|
+
var method = submitterOverride('formmethod', 'formMethod', 'method');
|
|
1672
|
+
var enctype = submitterOverride('formenctype', 'formEnctype', 'enctype');
|
|
1673
|
+
var isGet = String(method).toLowerCase() === 'get';
|
|
1674
|
+
var action;
|
|
1675
|
+
try {
|
|
1676
|
+
var actionUrl = new URL(actionAttr || frameUrl(), frameUrl());
|
|
1677
|
+
if (isGet) {
|
|
1678
|
+
var query = new URLSearchParams(new FormData(form, submitter)).toString();
|
|
1679
|
+
var hashIndex = actionUrl.href.indexOf('#');
|
|
1680
|
+
var withoutHash = hashIndex === -1 ? actionUrl.href : actionUrl.href.slice(0, hashIndex);
|
|
1681
|
+
var searchIndex = withoutHash.indexOf('?');
|
|
1682
|
+
var base = searchIndex === -1 ? withoutHash : withoutHash.slice(0, searchIndex);
|
|
1683
|
+
action = base + '?' + query + (hashIndex === -1 ? '' : actionUrl.href.slice(hashIndex));
|
|
1684
|
+
} else {
|
|
1685
|
+
action = String(actionUrl);
|
|
1686
|
+
}
|
|
1687
|
+
} catch (_) {
|
|
1688
|
+
return;
|
|
1689
|
+
}
|
|
1690
|
+
if (newWindowRequest) {
|
|
1691
|
+
requestOpenWindow(event, action);
|
|
1692
|
+
return;
|
|
1693
|
+
}
|
|
1694
|
+
event.preventDefault();
|
|
1695
|
+
var submitRequestId = ++navigationRequestSequence;
|
|
1696
|
+
// the activated button is a successful control of the submission:
|
|
1697
|
+
// an image button's point, or the entry the browser builds for a copy
|
|
1698
|
+
// of the button in a detached form, which keeps its default label
|
|
1699
|
+
// rule without firing formdata on the page's form.
|
|
1700
|
+
var submitterEntries = [];
|
|
1701
|
+
if (submitter && submitter.type === 'image') {
|
|
1702
|
+
var point = imageSubmitPoints.get(submitter) || [0, 0];
|
|
1703
|
+
var prefix = submitter.name ? submitter.name + '.' : '';
|
|
1704
|
+
submitterEntries = [[prefix + 'x', String(point[0])], [prefix + 'y', String(point[1])]];
|
|
1705
|
+
} else if (submitter) {
|
|
1706
|
+
var detachedForm = document.createElement('form');
|
|
1707
|
+
var detachedSubmitter = submitter.cloneNode(false);
|
|
1708
|
+
detachedSubmitter.removeAttribute('form');
|
|
1709
|
+
detachedForm.appendChild(detachedSubmitter);
|
|
1710
|
+
submitterEntries = Array.from(new FormData(detachedForm, detachedSubmitter));
|
|
1711
|
+
}
|
|
1712
|
+
pendingFormSubmissions[submitRequestId] = {
|
|
1713
|
+
form: form,
|
|
1714
|
+
url: action,
|
|
1715
|
+
isGet: isGet,
|
|
1716
|
+
action: actionAttr,
|
|
1717
|
+
method: method,
|
|
1718
|
+
enctype: enctype,
|
|
1719
|
+
submitter: submitter,
|
|
1720
|
+
submitterEntries: submitterEntries
|
|
1721
|
+
};
|
|
1722
|
+
window.parent.postMessage({
|
|
1723
|
+
__sootsimWebViewKind: 'webViewShouldStartLoad',
|
|
1724
|
+
requestId: submitRequestId,
|
|
1725
|
+
url: action,
|
|
1726
|
+
navigationType: 'formsubmit',
|
|
1727
|
+
isFormSubmit: true,
|
|
1728
|
+
isGetFormSubmit: isGet,
|
|
1729
|
+
sameDocument: false
|
|
1730
|
+
}, '*');
|
|
1731
|
+
}
|
|
1732
|
+
document.addEventListener('submit', holdFormSubmission);
|
|
1733
|
+
// a script's form.submit() fires no submit event, but webkit still asks
|
|
1734
|
+
// the policy delegate with a formsubmit action, so it takes the same hold;
|
|
1735
|
+
// replaying it as a url load would drop its method and body.
|
|
1736
|
+
var nativeFormSubmit = HTMLFormElement.prototype.submit;
|
|
1737
|
+
HTMLFormElement.prototype.submit = function () {
|
|
1738
|
+
var held = {
|
|
1739
|
+
target: this,
|
|
1740
|
+
submitter: null,
|
|
1741
|
+
defaultPrevented: false,
|
|
1742
|
+
preventDefault: function () { held.defaultPrevented = true; }
|
|
1743
|
+
};
|
|
1744
|
+
holdFormSubmission(held);
|
|
1745
|
+
if (!held.defaultPrevented) nativeFormSubmit.call(this);
|
|
1746
|
+
};
|
|
1747
|
+
// every other cross-document load the page starts itself (a script
|
|
1748
|
+
// assigning location, a reload) asks the same policy
|
|
1749
|
+
// delegate on iOS, as type other or reload. the bridge holds it like a
|
|
1750
|
+
// link; a navigation it performs on an allow verdict was already asked.
|
|
1751
|
+
// the policy verdict is asynchronous on iOS too, and webkit runs this
|
|
1752
|
+
// document's end scripts before the next load commits, so an allowed load
|
|
1753
|
+
// waits for a host's pending document-end injection.
|
|
1754
|
+
var performingDecidedNavigation = false;
|
|
1755
|
+
// a native form submit starts its navigation in a later task, after the
|
|
1756
|
+
// flag above is cleared, so the decided submit is let through by its body
|
|
1757
|
+
var decidedFormSubmission = false;
|
|
1758
|
+
function performDecidedNavigation(navigate) {
|
|
1759
|
+
var perform = function () {
|
|
1760
|
+
performingDecidedNavigation = true;
|
|
1761
|
+
try {
|
|
1762
|
+
navigate();
|
|
1763
|
+
} finally {
|
|
1764
|
+
performingDecidedNavigation = false;
|
|
1765
|
+
}
|
|
1766
|
+
};
|
|
1767
|
+
if (hook.documentEnd) hook.documentEnd.then(perform, perform);
|
|
1768
|
+
else perform();
|
|
1769
|
+
}
|
|
1770
|
+
navigation.addEventListener('navigate', function (event) {
|
|
1771
|
+
if (performingDecidedNavigation || !event.cancelable) return;
|
|
1772
|
+
var decidedSubmit = decidedFormSubmission && event.formData !== null;
|
|
1773
|
+
decidedFormSubmission = false;
|
|
1774
|
+
if (decidedSubmit) return;
|
|
1775
|
+
if (event.destination.sameDocument || event.navigationType === 'traverse') return;
|
|
1776
|
+
event.preventDefault();
|
|
1777
|
+
var requestId = ++navigationRequestSequence;
|
|
1778
|
+
pendingCrossDocumentNavigation[requestId] = event.destination.url;
|
|
1779
|
+
window.parent.postMessage({
|
|
1780
|
+
__sootsimWebViewKind: 'webViewShouldStartLoad',
|
|
1781
|
+
requestId: requestId,
|
|
1782
|
+
url: event.destination.url,
|
|
1783
|
+
navigationType: event.navigationType === 'reload' ? 'reload' : 'other',
|
|
1784
|
+
sameDocument: false
|
|
1785
|
+
}, '*');
|
|
1786
|
+
});
|
|
1787
|
+
var lastEditable = null;
|
|
1788
|
+
function editorIsEmpty(editor) {
|
|
1789
|
+
return 'value' in editor
|
|
1790
|
+
? String(editor.value || '').length === 0
|
|
1791
|
+
: String(editor.textContent || '').length === 0;
|
|
1792
|
+
}
|
|
1793
|
+
document.addEventListener('focusin', function (event) {
|
|
1794
|
+
var element = event.target;
|
|
1795
|
+
if (!element || !element.closest) return;
|
|
1796
|
+
var editor = element.closest('textarea, input, [contenteditable]:not([contenteditable="false"])');
|
|
1797
|
+
if (!editor) return;
|
|
1798
|
+
if (editor.tagName === 'INPUT' && !/^(text|search|email|tel|url|password|number)$/.test(editor.type || 'text')) return;
|
|
1799
|
+
lastEditable = editor;
|
|
1800
|
+
// webkit raises the keyboard only for focus with a live user gesture.
|
|
1801
|
+
// programmatic focus (element.focus(), autofocus, injected scripts)
|
|
1802
|
+
// focuses without a keyboard, which is also what the native oracle
|
|
1803
|
+
// shows on ios 27 where rnw's keyboardDisplayRequiresUserAction hack
|
|
1804
|
+
// is a silent no-op. transient activation alone is not enough: an
|
|
1805
|
+
// injected focus runs on the bridge after a real tap, so the eval
|
|
1806
|
+
// window below disqualifies injected focus explicitly. known gap:
|
|
1807
|
+
// userActivation stays true for seconds after a real tap, so a page
|
|
1808
|
+
// setTimeout focus inside that window still raises here where webkit
|
|
1809
|
+
// would not. the driver cannot tap into the iframe, so the
|
|
1810
|
+
// gesture-true branch has no conformance coverage either.
|
|
1811
|
+
var hasActivation = false;
|
|
1812
|
+
try {
|
|
1813
|
+
hasActivation = !!(navigator.userActivation && navigator.userActivation.isActive);
|
|
1814
|
+
} catch (_) {}
|
|
1815
|
+
window.parent.postMessage({
|
|
1816
|
+
__sootsimWebViewKind: 'webViewEditorFocus',
|
|
1817
|
+
inputType: editor.type || '',
|
|
1818
|
+
inputMode: editor.inputMode || '',
|
|
1819
|
+
enterKeyHint: editor.enterKeyHint || '',
|
|
1820
|
+
autoCapitalize: editor.autocapitalize || editor.getAttribute('autocapitalize') || '',
|
|
1821
|
+
autoCorrect: editor.autocorrect || editor.getAttribute('autocorrect') || '',
|
|
1822
|
+
spellCheck: editor.spellcheck,
|
|
1823
|
+
empty: editorIsEmpty(editor),
|
|
1824
|
+
userGesture: hasActivation && !evaluatingInjectedScript
|
|
1825
|
+
}, '*');
|
|
1826
|
+
}, true);
|
|
1827
|
+
document.addEventListener('focusout', function (event) {
|
|
1828
|
+
var element = event.target;
|
|
1829
|
+
if (!element || !element.closest) return;
|
|
1830
|
+
var editor = element.closest('textarea, input, [contenteditable]:not([contenteditable="false"])');
|
|
1831
|
+
if (!editor) return;
|
|
1832
|
+
if (editor.tagName === 'INPUT' && !/^(text|search|email|tel|url|password|number)$/.test(editor.type || 'text')) return;
|
|
1833
|
+
// a page-driven blur (script blur(), form submit, timer) resigns the
|
|
1834
|
+
// editor exactly like a host blur. focus moving to another editor is
|
|
1835
|
+
// not a blur: its focusin follows and the keyboard stays up.
|
|
1836
|
+
var next = event.relatedTarget;
|
|
1837
|
+
if (next && next.closest && next.closest('textarea, input, [contenteditable]:not([contenteditable="false"])')) return;
|
|
1838
|
+
lastEditable = null;
|
|
1839
|
+
window.parent.postMessage({
|
|
1840
|
+
__sootsimWebViewKind: 'webViewEditorPageBlur'
|
|
1841
|
+
}, '*');
|
|
1842
|
+
}, true);
|
|
1843
|
+
document.addEventListener('input', function (event) {
|
|
1844
|
+
var element = event.target;
|
|
1845
|
+
if (!element || !element.closest) return;
|
|
1846
|
+
var editor = element.closest('textarea, input, [contenteditable]:not([contenteditable="false"])');
|
|
1847
|
+
if (!editor) return;
|
|
1848
|
+
if (editor.tagName === 'INPUT' && !/^(text|search|email|tel|url|password|number)$/.test(editor.type || 'text')) return;
|
|
1849
|
+
// only a real edit to the focused editor counts: a synthetic input
|
|
1850
|
+
// event or one retargeted elsewhere never raises webkit's keyboard.
|
|
1851
|
+
if (!event.isTrusted || editor !== document.activeElement) return;
|
|
1852
|
+
// content changed inside an editor: typing, autocorrect, or
|
|
1853
|
+
// execCommand from an injected script. the native oracle raises the
|
|
1854
|
+
// keyboard on an insert into a focused field even when the focus
|
|
1855
|
+
// itself was programmatic, so the host needs this to match.
|
|
1856
|
+
window.parent.postMessage({
|
|
1857
|
+
__sootsimWebViewKind: 'webViewEditorState',
|
|
1858
|
+
empty: editorIsEmpty(editor)
|
|
1859
|
+
}, '*');
|
|
1860
|
+
}, true);
|
|
1861
|
+
window.addEventListener('message', function (event) {
|
|
1862
|
+
// only the shell host drives this frame. the host already checks that an
|
|
1863
|
+
// inbound message came from this exact iframe; this is the same check in
|
|
1864
|
+
// the other direction, and it covers injectJavaScript too.
|
|
1865
|
+
if (event.source !== window.parent) return;
|
|
1866
|
+
var payload = event.data;
|
|
1867
|
+
if (!payload || typeof payload !== 'object') return;
|
|
1868
|
+
if (payload.__sootsimWebViewKind === 'setMessageHandlers') {
|
|
1869
|
+
event.stopImmediatePropagation();
|
|
1870
|
+
if (!webKit || !Array.isArray(payload.names) || payload.names.some(function(name) { return typeof name !== 'string'; })) throw new Error('WKWebView handler update is invalid');
|
|
1871
|
+
setMessageHandlers(payload.names);
|
|
1872
|
+
return;
|
|
1873
|
+
}
|
|
1874
|
+
if (payload.__sootsimWebViewKind === 'webViewEditorBlur') {
|
|
1875
|
+
event.stopImmediatePropagation();
|
|
1876
|
+
if (lastEditable) lastEditable.blur();
|
|
1877
|
+
lastEditable = null;
|
|
1878
|
+
return;
|
|
1879
|
+
}
|
|
1880
|
+
if (payload.__sootsimWebViewKind === 'keyboardKeyPress') {
|
|
1881
|
+
event.stopImmediatePropagation();
|
|
1882
|
+
if (!lastEditable || !lastEditable.isConnected) return;
|
|
1883
|
+
lastEditable.focus({ preventScroll: true });
|
|
1884
|
+
var key = String(payload.key || '');
|
|
1885
|
+
var shouldApplyDefault = lastEditable.dispatchEvent(new KeyboardEvent('keydown', {
|
|
1886
|
+
key: key,
|
|
1887
|
+
bubbles: true,
|
|
1888
|
+
cancelable: true,
|
|
1889
|
+
composed: true
|
|
1890
|
+
}));
|
|
1891
|
+
if (shouldApplyDefault) {
|
|
1892
|
+
if (key.length === 1) document.execCommand('insertText', false, key);
|
|
1893
|
+
else if (key === 'Backspace') document.execCommand('delete', false);
|
|
1894
|
+
else if (key === 'Delete') document.execCommand('forwardDelete', false);
|
|
1895
|
+
else if (key === 'Enter') document.execCommand('insertLineBreak', false);
|
|
1896
|
+
}
|
|
1897
|
+
lastEditable.dispatchEvent(new KeyboardEvent('keyup', {
|
|
1898
|
+
key: key,
|
|
1899
|
+
bubbles: true,
|
|
1900
|
+
cancelable: true,
|
|
1901
|
+
composed: true
|
|
1902
|
+
}));
|
|
1903
|
+
// no explicit state post: an applied edit fires the input listener
|
|
1904
|
+
// above, which reports it. a prevented or non-text key changed
|
|
1905
|
+
// nothing, so there is nothing to report.
|
|
1906
|
+
return;
|
|
1907
|
+
}
|
|
1908
|
+
// the app's goBack, goForward and reload, asked through the policy
|
|
1909
|
+
// delegate like any load the page starts
|
|
1910
|
+
if (payload.__sootsimWebViewKind === 'webViewTraverse' && typeof payload.url === 'string') {
|
|
1911
|
+
event.stopImmediatePropagation();
|
|
1912
|
+
var traversalId = ++navigationRequestSequence;
|
|
1913
|
+
pendingCrossDocumentNavigation[traversalId] = payload.url;
|
|
1914
|
+
pendingTraversals[traversalId] = true;
|
|
1915
|
+
window.parent.postMessage({
|
|
1916
|
+
__sootsimWebViewKind: 'webViewShouldStartLoad',
|
|
1917
|
+
requestId: traversalId,
|
|
1918
|
+
url: payload.url,
|
|
1919
|
+
navigationType: 'backforward',
|
|
1920
|
+
sameDocument: false
|
|
1921
|
+
}, '*');
|
|
1922
|
+
return;
|
|
1923
|
+
}
|
|
1924
|
+
if (payload.__sootsimWebViewKind === 'webViewReload') {
|
|
1925
|
+
event.stopImmediatePropagation();
|
|
1926
|
+
location.reload();
|
|
1927
|
+
return;
|
|
1928
|
+
}
|
|
1929
|
+
if (payload.__sootsimWebViewKind === 'webViewNavigationDecision') {
|
|
1930
|
+
event.stopImmediatePropagation();
|
|
1931
|
+
var submission = pendingFormSubmissions[payload.requestId];
|
|
1932
|
+
if (submission !== undefined) {
|
|
1933
|
+
delete pendingFormSubmissions[payload.requestId];
|
|
1934
|
+
if (payload.shouldStart !== true || !submission.form.isConnected) return;
|
|
1935
|
+
// a get submit is a navigation to the asked url. any other method
|
|
1936
|
+
// submits the form natively with the submitter's action, method
|
|
1937
|
+
// and enctype, so the body survives. the native submit cannot name
|
|
1938
|
+
// a submitter, so hidden fields carry its entries at its place in
|
|
1939
|
+
// tree order, and the entry list is built synchronously, so every
|
|
1940
|
+
// stand-in comes back out right after.
|
|
1941
|
+
if (submission.isGet) {
|
|
1942
|
+
performDecidedNavigation(function () { location.href = submission.url; });
|
|
1943
|
+
return;
|
|
1944
|
+
}
|
|
1945
|
+
var submittedForm = submission.form;
|
|
1946
|
+
var overrides = { action: submission.action, method: submission.method, enctype: submission.enctype };
|
|
1947
|
+
var savedAttributes = Object.keys(overrides).map(function (name) {
|
|
1948
|
+
return [name, submittedForm.getAttribute(name)];
|
|
1949
|
+
});
|
|
1950
|
+
var anchor = submission.submitter && submission.submitter.isConnected ? submission.submitter : null;
|
|
1951
|
+
var standIns = submission.submitterEntries.map(function (entry) {
|
|
1952
|
+
var input = document.createElement('input');
|
|
1953
|
+
input.type = 'hidden';
|
|
1954
|
+
input.name = entry[0];
|
|
1955
|
+
input.value = entry[1];
|
|
1956
|
+
if (anchor && anchor.hasAttribute('form')) input.setAttribute('form', anchor.getAttribute('form'));
|
|
1957
|
+
if (anchor) anchor.insertAdjacentElement('afterend', input);
|
|
1958
|
+
else submittedForm.appendChild(input);
|
|
1959
|
+
anchor = anchor ? input : null;
|
|
1960
|
+
return input;
|
|
1961
|
+
});
|
|
1962
|
+
Object.keys(overrides).forEach(function (name) {
|
|
1963
|
+
submittedForm.setAttribute(name, overrides[name]);
|
|
1964
|
+
});
|
|
1965
|
+
performDecidedNavigation(function () {
|
|
1966
|
+
decidedFormSubmission = true;
|
|
1967
|
+
nativeFormSubmit.call(submittedForm);
|
|
1968
|
+
standIns.forEach(function (input) { input.remove(); });
|
|
1969
|
+
savedAttributes.forEach(function (saved) {
|
|
1970
|
+
if (saved[1] === null) submittedForm.removeAttribute(saved[0]);
|
|
1971
|
+
else submittedForm.setAttribute(saved[0], saved[1]);
|
|
1972
|
+
});
|
|
1973
|
+
});
|
|
1974
|
+
return;
|
|
1975
|
+
}
|
|
1976
|
+
var allowedUrl = pendingCrossDocumentNavigation[payload.requestId];
|
|
1977
|
+
if (allowedUrl === undefined) return;
|
|
1978
|
+
var traversal = pendingTraversals[payload.requestId] === true;
|
|
1979
|
+
delete pendingCrossDocumentNavigation[payload.requestId];
|
|
1980
|
+
delete pendingTraversals[payload.requestId];
|
|
1981
|
+
if (payload.shouldStart !== true) return;
|
|
1982
|
+
// a traversal moves within the list, so it adds no browser history
|
|
1983
|
+
performDecidedNavigation(function () {
|
|
1984
|
+
if (traversal) location.replace(allowedUrl);
|
|
1985
|
+
else location.href = allowedUrl;
|
|
1986
|
+
});
|
|
1987
|
+
return;
|
|
1988
|
+
}
|
|
1989
|
+
if (payload.__sootsimWebViewKind === 'evaluateJavaScript') {
|
|
1990
|
+
event.stopImmediatePropagation();
|
|
1991
|
+
var result;
|
|
1992
|
+
try {
|
|
1993
|
+
var value = (0, eval)(String(payload.js || ''));
|
|
1994
|
+
try { result = value === undefined ? { undefined: true } : { value: nativeValue(value, []) }; }
|
|
1995
|
+
catch (_) { result = { errorCode: 5, errorInfo: { NSLocalizedDescription: 'JavaScript execution returned a result of an unsupported type' } }; }
|
|
1996
|
+
} catch (error) {
|
|
1997
|
+
// DEGRADED(PEACH-SWIFT-WEBKIT-EXCEPTION-METADATA): native exception line/column remain unbuilt.
|
|
1998
|
+
result = { errorCode: 4, errorInfo: { NSLocalizedDescription: 'A JavaScript exception occurred', WKJavaScriptExceptionMessage: String(error), WKJavaScriptExceptionSourceURL: String(document.baseURI) } };
|
|
1999
|
+
}
|
|
2000
|
+
result.title = String(document.title || '');
|
|
2001
|
+
window.parent.postMessage({ __sootsimWebViewKind: 'webKitEvaluation', requestId: payload.requestId, result: result }, '*');
|
|
2002
|
+
return;
|
|
2003
|
+
}
|
|
2004
|
+
if (payload.__sootsimWebViewKind !== 'injectJavaScript') return;
|
|
2005
|
+
event.stopImmediatePropagation();
|
|
2006
|
+
evaluatingInjectedScript = true;
|
|
2007
|
+
try {
|
|
2008
|
+
(0, eval)(String(payload.js || ''));
|
|
2009
|
+
} catch (err) {
|
|
2010
|
+
setTimeout(function () { throw err; }, 0);
|
|
2011
|
+
} finally {
|
|
2012
|
+
evaluatingInjectedScript = false;
|
|
2013
|
+
}
|
|
2014
|
+
}, true);
|
|
2015
|
+
}`;
|
|
2016
|
+
var WEBVIEW_SAME_ORIGIN_BOOTSTRAP_SOURCE = `(function () {
|
|
2017
|
+
if (window[Symbol.for(${JSON.stringify(WEBVIEW_FRAME_HOOK)})]) return;
|
|
2018
|
+
var element = null;
|
|
2019
|
+
try {
|
|
2020
|
+
element = window.frameElement;
|
|
2021
|
+
} catch (_) {}
|
|
2022
|
+
var raw = element && element.getAttribute(${JSON.stringify(WEBVIEW_FRAME_CONFIG_ATTRIBUTE)});
|
|
2023
|
+
if (!raw) return;
|
|
2024
|
+
var config = JSON.parse(raw);
|
|
2025
|
+
(${WEBVIEW_FRAME_BRIDGE_SOURCE})(config);
|
|
2026
|
+
if (config.beforeContent) (0, eval)(config.beforeContent);
|
|
2027
|
+
})();`;
|
|
2028
|
+
var WEBVIEW_HOST_BOOTSTRAP_SOURCE = `function (timingName) {
|
|
2029
|
+
if (window === window.top || window.parent !== window.top) return;
|
|
2030
|
+
var entry = performance.getEntriesByType('navigation')[0];
|
|
2031
|
+
var timings = (entry && entry.serverTiming) || [];
|
|
2032
|
+
for (var index = 0; index < timings.length; index++) {
|
|
2033
|
+
if (timings[index].name !== timingName) continue;
|
|
2034
|
+
if (window.name.indexOf(${JSON.stringify(WEBVIEW_FRAME_NAME_PREFIX)}) === 0) window.name = '';
|
|
2035
|
+
(${WEBVIEW_FRAME_BRIDGE_SOURCE})(JSON.parse(decodeURIComponent(timings[index].description)));
|
|
2036
|
+
// the host runs injectedJavaScript once the document is parsed, after the
|
|
2037
|
+
// page's own DOMContentLoaded listeners, as WebKit runs a document-end
|
|
2038
|
+
// WKUserScript after it dispatches DOMContentLoaded.
|
|
2039
|
+
var host = window[${JSON.stringify(WEBVIEW_HOST_BINDING)}];
|
|
2040
|
+
var hook = window[Symbol.for(${JSON.stringify(WEBVIEW_FRAME_HOOK)})];
|
|
2041
|
+
window.addEventListener('DOMContentLoaded', function () {
|
|
2042
|
+
hook.documentEnd = host({ kind: 'documentEnd' });
|
|
2043
|
+
});
|
|
2044
|
+
return;
|
|
2045
|
+
}
|
|
2046
|
+
}`;
|
|
2047
|
+
|
|
919
2048
|
// ../peach-engine/src/remote-stream/remoteEngineParam.ts
|
|
920
2049
|
function readRemoteEngineParam(search, hash) {
|
|
921
2050
|
const fromQuery = new URLSearchParams(search).get("remoteEngine");
|
|
@@ -3376,10 +4505,13 @@ var device = {
|
|
|
3376
4505
|
reapOwnedBrowser();
|
|
3377
4506
|
throw error;
|
|
3378
4507
|
}
|
|
3379
|
-
await
|
|
4508
|
+
await automateWebViewFrames(
|
|
3380
4509
|
_context,
|
|
3381
|
-
|
|
3382
|
-
|
|
4510
|
+
webViewAutomationNames(
|
|
4511
|
+
`peachwv${(0, import_crypto.randomBytes)(12).toString("hex")}`,
|
|
4512
|
+
WEBVIEW_HOST_BOOTSTRAP_SOURCE
|
|
4513
|
+
),
|
|
4514
|
+
webViewAutomationHelpers
|
|
3383
4515
|
);
|
|
3384
4516
|
await _context.exposeBinding("__sootsimHostCapture", async (source, value) => {
|
|
3385
4517
|
const request = readBrowserCompositeCaptureRequest(value);
|