Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions apps/desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,26 @@ fn application_url(url: &tauri::Url) -> bool {

fn preview_url(url: &tauri::Url) -> bool {
// Embedded PDF/HTML previews use blobs minted by the application itself.
url.scheme() == "blob"
&& tauri::Url::parse(url.path()).is_ok_and(|origin| application_url(&origin))
// HTML previews with JavaScript load the static oxbit-preview shell.
url.scheme() == "oxbit-preview"
|| url.scheme() == "blob"
&& tauri::Url::parse(url.path()).is_ok_and(|origin| application_url(&origin))
}

#[cfg(test)]
mod preview_tests {
use super::preview_url;

#[test]
fn only_application_blob_urls_can_navigate() {
fn only_application_previews_can_navigate() {
assert!(preview_url(
&"blob:tauri://localhost/preview".parse().unwrap()
));
assert!(preview_url(
&"oxbit-preview://localhost/preview-shell.html"
.parse()
.unwrap()
));
for url in [
"blob:https://example.com/preview",
"blob:tauri://other/preview",
Expand Down
26 changes: 26 additions & 0 deletions tests/desktop/workbench.e2e.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,32 @@ describe("Oxbit native workbench", () => {
assert.match(JSON.stringify(result.search), /hello.ts/);
assert.equal(result.clipboard, "Oxbit native clipboard café");
});
it("runs HTML preview JavaScript through the oxbit-preview shell in a trusted folder", async () => {
await browser.execute(async () => {
const { filesystem, runtime, workbench } = globalThis.__oxbit;
await runtime.trust(true);
addEventListener("message", (event) => {
if (event.data?.type === "native-preview-script")
globalThis.__nativePreviewScript = event.data.text;
});
await filesystem.write(
"preview.html",
'<!doctype html><h1 id="title">Static</h1><script>document.getElementById("title").textContent = "Script ran"; parent.postMessage({ type: "native-preview-script", text: document.getElementById("title").textContent }, "*");</script>',
{ expectedRevision: null },
);
await workbench.openFile("preview.html", { preview: false });
await workbench.run("preview.html");
});
await browser.waitUntil(
() => browser.execute(() => globalThis.__nativePreviewScript),
{ timeout: 20000, timeoutMsg: "The preview page's script did not run" },
);
assert.equal(
await browser.execute(() => globalThis.__nativePreviewScript),
"Script ran",
);
assert.equal(await $(".html-preview-scripts").isExisting(), false);
});
it("completes TypeScript, cancels a real task, and stages a Git file in the native host", async () => {
const completion = await browser.execute(async () => {
const z = globalThis.__oxbit;
Expand Down
Loading