tabs.saveAsPDF()
保存当前页面为 PDF 文件。这将打开一个对话框,由操作系统提供,询问用户想要保存 PDF 文件的位置。
这是一个返回 Promise
的异步函数。
语法
js
let saving = browser.tabs.saveAsPDF(
pageSettings, // 对象
);
参数
pageSettings
-
object
。保存页面的设置(一个tabs.PageSettings
对象)。这个对象必须提供,但其中的所有属性都是可选的。任何未指定的属性将使用默认值,详细的默认值列表请参考PageSettings
文档。
返回值
一个 Promise
,当对话框关闭时其会兑现一个状态字符串。可能的字符串包括:
- “saved”
- “replaced”
- “canceled”
- “not_saved”
- “not_replaced”
示例
在这个示例中,后台脚本监听浏览器操作按钮的点击事件,然后尝试将当前活动的标签页保存为 PDF 文件,并将保存结果记录在控制台中:
js
browser.browserAction.onClicked.addListener(() => {
browser.tabs.saveAsPDF({}).then((status) => {
console.log(status);
});
});
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | ||||||
---|---|---|---|---|---|---|---|
saveAsPDF |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.