Skip to content

Commit

Permalink
[CRX] Add work-around for Chrome crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob--W committed Sep 8, 2024
1 parent 4327502 commit b3a0ad0
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion extensions/chromium/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,21 @@ function maybeRenderPdfDoc(isNotPOST) {

// In any case, load the viewer.
console.log(`Detected PDF via document, opening viewer for ${document.URL}`);
location.href = getEmbeddedViewerURL(document.URL);

// Ideally we would use logic consistent with the DNR logic, like this:
// location.href = getEmbeddedViewerURL(document.URL);
// ... unfortunately, this causes Chrome to crash until version 129, fixed by
// https://chromium.googlesource.com/chromium/src/+/8c42358b2cc549553d939efe7d36515d80563da7%5E%21/
// Work around this by replacing the body with an iframe of the viewer.
// Interestingly, Chrome's built-in PDF viewer uses a similar technique.
const shadowRoot = document.body.attachShadow({ mode: "closed" });
const iframe = document.createElement("iframe");
iframe.style.position = "absolute";
iframe.style.top = "0";
iframe.style.left = "0";
iframe.style.width = "100%";
iframe.style.height = "100%";
iframe.style.border = "0 none";
iframe.src = getEmbeddedViewerURL(document.URL);
shadowRoot.append(iframe);
}

0 comments on commit b3a0ad0

Please sign in to comment.