browser.runtime.sendMessage API 在 Firefox 扩展上发送大数据缓慢
browser.runtime.sendMessage API send large data slowly on Firefox extension
我使用 browser.runtime.sendMessage API 的 firefox 扩展(firefox 54-64 位)发送消息有从 contentscript 到后台的大量二进制数据。
发送消息非常慢,使 firefox 在 3-5 秒内没有响应,具体取决于 contentscript 发送的数据大小。然后正常工作,后台接收消息。
关于chrome sendMessage API 工作很快,非常非常流畅。
如何在 firefox 中修复它?
browser.runtime.sendMessage(tab.id, { name: "sendScreen", data: { screen: screen} })
对象中的屏幕值是二进制数据(长度为~1135609的数组)。
在background.js我添加监听消息:
browser.runtime.onMessage.addListener (message, sender, sendResponse);
清单文件:
{
"name": "abc",
"background": {
"page": "background.html"
},
"browser_action": {
"default_icon": "icons/icon_19.png",
"default_popup": "login.html",
},
"content_scripts": [
{
"web_accessible_resources": [
"js/contentscripts/Browser.js",
],
"js": [
"js/contentscripts/ContentScript.js"
],
"matches": [
"file://*/*",
"http://*/*",
"https://*/*"
],
"run_at": "document_end",
"all_frames": true
},
{
"js": [
"js/contentscripts/Browser.js",
],
"matches": [
"file://*/*",
"http://*/*",
"https://*/*"
],
"run_at": "document_start",
"all_frames": true
}
],
"icons": {
"16": "icons/icon_16.png",
"19": "icons/icon_19.png"
},
"incognito": "spanning",
"permissions": [
"activeTab",
"tabs",
"http://*/*",
"https://*/*",
"<all_urls>"
],
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}
如果bug 1356546 mentioned didn't resolve the issue then file a new firefox bug.
否则你可以尝试像评论中提到的那样拆分你的数据,这不会减少总时间,但它可能会减少对 UX 的影响,或者在他们修复他们的 webextensions 之前不支持 Firefox错误。
我使用 browser.runtime.sendMessage API 的 firefox 扩展(firefox 54-64 位)发送消息有从 contentscript 到后台的大量二进制数据。
发送消息非常慢,使 firefox 在 3-5 秒内没有响应,具体取决于 contentscript 发送的数据大小。然后正常工作,后台接收消息。
关于chrome sendMessage API 工作很快,非常非常流畅。
如何在 firefox 中修复它?
browser.runtime.sendMessage(tab.id, { name: "sendScreen", data: { screen: screen} })
对象中的屏幕值是二进制数据(长度为~1135609的数组)。
在background.js我添加监听消息:
browser.runtime.onMessage.addListener (message, sender, sendResponse);
清单文件:
{
"name": "abc",
"background": {
"page": "background.html"
},
"browser_action": {
"default_icon": "icons/icon_19.png",
"default_popup": "login.html",
},
"content_scripts": [
{
"web_accessible_resources": [
"js/contentscripts/Browser.js",
],
"js": [
"js/contentscripts/ContentScript.js"
],
"matches": [
"file://*/*",
"http://*/*",
"https://*/*"
],
"run_at": "document_end",
"all_frames": true
},
{
"js": [
"js/contentscripts/Browser.js",
],
"matches": [
"file://*/*",
"http://*/*",
"https://*/*"
],
"run_at": "document_start",
"all_frames": true
}
],
"icons": {
"16": "icons/icon_16.png",
"19": "icons/icon_19.png"
},
"incognito": "spanning",
"permissions": [
"activeTab",
"tabs",
"http://*/*",
"https://*/*",
"<all_urls>"
],
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}
如果bug 1356546 mentioned didn't resolve the issue then file a new firefox bug.
否则你可以尝试像评论中提到的那样拆分你的数据,这不会减少总时间,但它可能会减少对 UX 的影响,或者在他们修复他们的 webextensions 之前不支持 Firefox错误。