Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

fix(windows): open external links from iframes in the system browser

crispyaus207323477bee
diff --git a/src-tauri/src/inject/event.js b/src-tauri/src/inject/event.js
index 1319ae2f..1ac56ef1 100644
--- a/src-tauri/src/inject/event.js
+++ b/src-tauri/src/inject/event.js
@@ -792,6 +792,13 @@ document.addEventListener("DOMContentLoaded", () => {
return;
}
+ // WebView2 runs this script in subframes too, where IPC is denied for the
+ // frame's own origin. Hand the link to the top page like frame_links.js.
+ if (window.top !== window) {
+ window.top.postMessage({ type: "pake:frame-external-link", url }, "*");
+ return;
+ }
+
invoke("plugin:shell|open", {
path: url,
}).catch((error) => {
diff --git a/tests/unit/event-link-guard.test.js b/tests/unit/event-link-guard.test.js
index 67da3a7e..3f9878fe 100644
--- a/tests/unit/event-link-guard.test.js
+++ b/tests/unit/event-link-guard.test.js
@@ -9,6 +9,7 @@ function loadEventHelpers({
initialZoom = null,
downloadError = null,
nativeDownloads = false,
+ topWindow = null,
} = {}) {
const source = ["link_policy.js", "event.js"]
.map((file) =>
@@ -121,6 +122,7 @@ function loadEventHelpers({
},
};
context.window.navigator = context.navigator;
+ context.window.top = topWindow || context.window;
if (withTauri) {
context.window.__TAURI__ = {
core: { invoke },
@@ -862,6 +864,36 @@ describe("event link guard", () => {
]);
});
+ it("hands external links from a subframe to the top page instead of IPC", () => {
+ // WebView2 injects event.js into subframes, whose origin has no IPC grant.
+ const messages = [];
+ const context = loadEventHelpers({
+ withTauri: true,
+ topWindow: { postMessage: (message) => messages.push(message) },
+ });
+ runDomReady(context);
+
+ expect(context.window.open("https://outside.example/launch")).toBeNull();
+ const event = makeClickEvent(
+ makeAnchor("https://outside.example/page", "_new"),
+ );
+ getClickGuard(context)(event);
+
+ expect(event.preventDefault).toHaveBeenCalled();
+ expect(messages).toEqual([
+ {
+ type: "pake:frame-external-link",
+ url: "https://outside.example/launch",
+ },
+ { type: "pake:frame-external-link", url: "https://outside.example/page" },
+ ]);
+ expect(
+ context.invokeCalls.filter(
+ ([command]) => command === "plugin:shell|open",
+ ),
+ ).toEqual([]);
+ });
+
it("bridges Web Badging API calls to explicit badge commands", async () => {
const { navigator, invokeCalls } = loadEventHelpers({ withTauri: true });