如何从谷歌浏览器扩展名获取PDF文件的URL [英] how to get the URL of a PDF file from a google chrome extension
问题描述
去年,我开发了适用于PDF文件的google扩展程序. 我使用以下功能来获取PDF文件的URL:
Last year I developed a google extension that worked on PDF files. I used the following function in order to get the URL of the PDF file:
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;
}
现在,最新版本的Google Chrome浏览器不再提供src属性.
Now, the latest version of Google Chrome does not provide the src attribue anymore.
<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>
如何获取具有最新版本的Google Chrome浏览器的PDF文件的网址?
How can I get the URL of the PDF file with the latest version of Google Chrome?
推荐答案
显然,现在可以通过内部chrome扩展名chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/
来查看PDF.
Apparently PDF is now viewed through an internal chrome extension chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/
.
除了使用window.location.href
之外,您还可以使用document.getElementsByTagName("embed")[0].baseURI
Aside from using window.location.href
you can use document.getElementsByTagName("embed")[0].baseURI
这篇关于如何从谷歌浏览器扩展名获取PDF文件的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!