如何使用 fetch 在 firefox 或 chrome 网络扩展中获取网页的 HTML 来源?
How to use fetch to get the HTML source of a webpage in a firefox or chrome web extension?
我正在尝试使用 fetch
在 Chrome/Firefox 网络扩展中获取 https://smmry.com/
的 HTML 来源。
这是我的manifest.json
{
"manifest_version": 2,
"name": "To_Be_Done",
"version": "1.0",
"description": "To_Be_Done",
"permissions": [
"tabs",
"*://*.smmry.com/*"
],
"icons": {
"48": "icons/border-48.png"
},
"browser_action": {
"browser_style": true,
"default_popup": "popup/choose_page.html",
"default_icon": {
"16": "icons/news-icon-16.png",
"32": "icons/news-icon-32.png"
}
}
}
每当我的扩展按钮被点击时,我都想获得 smmry.com 的 HTML 来源。但是,我不知道如何实现 fetch()
方法来做到这一点。我已经通读了文档,但我仍然感到困惑。
谁能举个例子?
我知道怎么做了。以下returns html 文件的“https://smmry.com”为字符串。
fetch('https://smmry.com/')
.then((resp) => resp.text())
.then(function (data) {
})
我正在尝试使用 fetch
在 Chrome/Firefox 网络扩展中获取 https://smmry.com/
的 HTML 来源。
这是我的manifest.json
{
"manifest_version": 2,
"name": "To_Be_Done",
"version": "1.0",
"description": "To_Be_Done",
"permissions": [
"tabs",
"*://*.smmry.com/*"
],
"icons": {
"48": "icons/border-48.png"
},
"browser_action": {
"browser_style": true,
"default_popup": "popup/choose_page.html",
"default_icon": {
"16": "icons/news-icon-16.png",
"32": "icons/news-icon-32.png"
}
}
}
每当我的扩展按钮被点击时,我都想获得 smmry.com 的 HTML 来源。但是,我不知道如何实现 fetch()
方法来做到这一点。我已经通读了文档,但我仍然感到困惑。
谁能举个例子?
我知道怎么做了。以下returns html 文件的“https://smmry.com”为字符串。
fetch('https://smmry.com/')
.then((resp) => resp.text())
.then(function (data) {
})