gpt4 book ai didi

javascript - Chrome 扩展主机注册在 Windows 中不起作用

转载 作者:行者123 更新时间:2023-11-28 03:28:59 25 4
gpt4 key购买 nike

我想通过单击网页上的按钮来运行控制台应用程序控制台应用程序将获取信息并放入剪贴板,然后我将在网页上获取该信息。我正在关注this blog
我这样做了 3-4 次,所有其他事情看起来都很好,但控制台应用程序没有被调用/执行。

我收到这些错误。
在网页控制台上
未检查的runtime.lastError:消息端口在收到响应之前关闭。
在后台文件
未选中的runtime.lastError:找不到指定的 native 消息传递主机。
未检查的runtime.lastError:消息端口在收到响应之前关闭。

我的代码是

list .json

{
"name": "EID Reader",
"version": "1.0",
"manifest_version": 2,
"description": "Read Emirates ID",

"permissions": [ "contextMenus", "activeTab", "clipboardRead", "nativeMessaging" ],
"icons": {
"16": "eid16.png",
"48": "eid48.png",
"128": "eid128.png"
},
"background": {
"scripts": [ "eid.js" ]
},
"content_scripts": [
{
"matches": [ "http://*/*", "https://*/*", "file://*/*"],
"js": [ "content_script.js", "jquery-3.3.1.js" ],
"all_frames": true,
"run_at": "document_start"
}
]
}

content_script.js

    // Listener to catch the event raised by the webpage button
document.addEventListener("EID_EVENT", function (data) {
// send message to background process to read emirates ID and send back the data
chrome.runtime.sendMessage("ifligfijbkpijeafdfbpljjibfbppmeb", function (response) {
});
});

// Listener to catch the data coming from the background process
chrome.extension.onMessage.addListener(function (msg, sender, sendResponse) {
if (msg.action == 'EID_DATA') {
//Parse the data and fill the form accordingly
try {
var json = $.parseJSON(msg.response);
$(json).each(function (i, val) {
$.each(val, function (key, value) {
if (key == 'EIDNumber')
$("#txtNumber").val(value);
if (key == 'Name')
$("#txtName").val(value);
if (key == 'Email')
$("#txtEmail").val(value);
if (key == 'PassportNumber')
$("#txtPassport").val(value);
});
});
}
catch (e) {
var error = "error" + e;
}
}
});

eid.js(背景)

var port = null;
var tabId = null;
/* listener for messages coming from the content_scrip */
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
tabId=sender.tab.id;
var hostName = "ae.eid.chrome";
port = chrome.runtime.connectNative(hostName);
port.onDisconnect.addListener(onDisconnected);
});


/* THIS WILL BE CALLED ONCE EXE FINISH */
function onDisconnected() {

port = null;
SendResponse();
}

function SendResponse() {
//create a textarea, focus on it, and make a "paste" command to get the clipboard, then send the pasted value back to the content_script
bg = chrome.extension.getBackgroundPage();
bg.document.body.innerHTML = ""; // clear the background page
var helper = null;
if (helper == null) {
helper = bg.document.createElement("textarea");
helper.style.position = "absolute";
helper.style.border = "none";
document.body.appendChild(helper);
}

//Focus the textarea
helper.select();

// perform a Paste in the selected control, here the textarea
bg.document.execCommand("Paste");

// Send data back to content_script
chrome.tabs.sendMessage(tabId, { action: "EID_DATA", response: helper.value }, function (response) { });
}

ae.eid.chrome.json

{
"name": "ae.eid.chrome",
"description": "chrome extension to read EID",
"path": "EIDSampleConsole.exe",
"type": "stdio",
"allowed_origins": [
"chrome-extension://ifligfijbkpijeafdfbpljjibfbppmeb/"
]
}

安装主机.bat

REG ADD "HKCU\Software\Google\Chrome\NativeMessagingHosts\ae.eid.chrome" /ve /t REG_SZ /d "%~dp0ae.eid.chrome.json" /f

我花了两天没有得到任何帮助。
我是否犯了一些错误,或者 Google Chrome 阻止或更改了注册主机的方式。

最佳答案

我已经解决了所有问题并将所有步骤发布在

http://www.codingsips.com/emirates-id-reader-and-google-chrome-via-extension-and-console-app/

我还发布了 Chrome 扩展程序,如果您按照上述步骤操作,相同的扩展程序也适用于您

Chrome 扩展

https://chrome.google.com/webstore/detail/adcs-eid-reader/ipcncgpbppgjclagpdlodiiapmggolkf

关于javascript - Chrome 扩展主机注册在 Windows 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58341655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com