去年我开发了一个适用于 PDF 文件的谷歌扩展程序。
我使用以下函数来获取 PDF 文件的 URL:
function getPDFUrl(): String {
const e = document.body.firstElementChild;
if (e.id != "plugin" || e.type != "application/pdf" || e.src == undefined)
throw new Error("This does not look like a PDF document");
return e.src;
}
现在,最新版本的谷歌浏览器不再提供 src 属性。
<html>
<body style="height: 100%; width: 100%; overflow: hidden; margin:0px; background-color: rgb(82, 86, 89);">
<embed style="position:absolute; left: 0; top: 0;" width="100%" height="100%" src="about:blank" type="application/pdf" internalid="3568AA495C01C5F2079A85384CEE54EE">
</body>
</html>
如何使用最新版本的谷歌浏览器获取 PDF 文件的 URL?
最佳答案
显然,现在可以通过内部 chrome 扩展查看 PDF chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/
.
除了使用 window.location.href
您可以使用 document.querySelector("embed").baseURI
关于javascript - 如何从谷歌浏览器扩展中获取 PDF 文件的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58197818/