在我的Google Chrome扩展中,background.js
定义了这个函数:
function submitMHTML() {
console.log("entered submitMHTML()");
chrome.tabs.query(
{active: true, lastFocusedWindow: true},
function(array_of_Tabs) {
if (array_of_Tabs.length > 0) {
var tab = array_of_Tabs[0];
console.log("submitMHTML() found the active tab has an ID of " + tab.id);
chrome.pageCapture.saveAsMHTML(
tab.id,
function(mhtml) {
var xhr = new XMLHttpRequest(), formData = new FormData();
formData.append("mhtml", mhtml);
formData.append("surveyID", localStorage["ID"]);
xhr.open("POST", "http://localhost:3000/task/mhtml", true);
xhr.setRequestHeader('Authorization', 'Token token=<redacted>');
xhr.send(formData);
console.log("submitMHTML() sent mhtml to server");
}
)
}
}
);
}
字符串
那么,为什么我会在我的控制台上看到这个呢?
entered submitMHTML()
submitMHTML() found the active tab has an ID of 450
extensions::uncaught_exception_handler:8 Error in response to tabs.query: Error: Invocation of form pageCapture.saveAsMHTML(integer, function) doesn't match definition pageCapture.saveAsMHTML(object details, function callback)
at Object.callback (chrome-extension://nmlggmkodifcibdmpdaohpmhljbkgpdb/background.js:194:28)
at submitMHTML (chrome-extension://nmlggmkodifcibdmpdaohpmhljbkgpdb/background.js:188:15)
at submitResult (chrome-extension://nmlggmkodifcibdmpdaohpmhljbkgpdb/background.js:249:5)
at HTMLButtonElement.<anonymous> (chrome-extension://nmlggmkodifcibdmpdaohpmhljbkgpdb/popup.js:25:78)
型
顺便说一句,控制台日志中的行号排列如下:
- 第194章:
chrome.pageCapture.saveAsMHTML(
- 188:
chrome.tabs.query
- 249:
submitMTHML();
(在另一个函数中)
chrome.pageCapture.saveAsMHTML()
被定义为here。该函数返回一个blob,我应该能够以这种方式将其附加到表单。我已经在清单中提供了必要的权限。
3条答案
按热度按时间ioekq8ef1#
错误解释了这一点。使用
chrome.pageCapture.saveAsMHTML({ tabId: tab.id }, callback)
而不是chrome.pageCapture.saveAsMHTML(tab.id, callback)
xdyibdwo2#
虽然这个问题已经过去很久了,但我最近才尝试使用这个API。
字符串
g2ieeal73#
我在这里找到了一个很好的解决方案,保存页面内容的解决方案
字符串