SignalR 集线器未在 Edge 中加载以进行扩展
SignalR hubs not loading in Edge for extension
澄清一下,这个问题是关于基于 Chromium 之前版本的 Edge。
我正在尝试将 Chrome 扩展转换为 Edge 扩展,并使用 Microsoft Edge 扩展工具包进行了转换。该扩展在一个简单的 Windows 表单应用程序中连接到本地 SignalR 集线器 运行,以将消息从 Web 应用程序来回传递到外部连接的设备。我在尝试连接时从 SignalR 收到此错误:
Error: SignalR: Error loading hubs. Ensure your hubs reference is correct, e.g. script src='/signalr/js'>/script>.
我发现它位于 SignalR jquery 文件中,并且上面有一条注释说当正确引用集线器时错误消息将被替换。我可以导航到 localhost:9562/signalr/hubs 并从中心查看以下代码。
/*!
* ASP.NET SignalR JavaScript Library v2.2.2
* http://signalr.net/
*
* Copyright (c) .NET Foundation. All rights reserved.
* Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
*
*/
/// <reference path="..\..\SignalR.Client.JS\Scripts\jquery-1.6.4.js" />
/// <reference path="jquery.signalR.js" />
(function ($, window, undefined) {
/// <param name="$" type="jQuery" />
"use strict";
if (typeof ($.signalR) !== "function") {
throw new Error("SignalR: SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/js.");
}
var signalR = $.signalR;
function makeProxyCallback(hub, callback) {
return function () {
// Call the client hub method
callback.apply(hub, $.makeArray(arguments));
};
}
function registerHubProxies(instance, shouldSubscribe) {
var key, hub, memberKey, memberValue, subscriptionMethod;
for (key in instance) {
if (instance.hasOwnProperty(key)) {
hub = instance[key];
if (!(hub.hubName)) {
// Not a client hub
continue;
}
if (shouldSubscribe) {
// We want to subscribe to the hub events
subscriptionMethod = hub.on;
} else {
// We want to unsubscribe from the hub events
subscriptionMethod = hub.off;
}
// Loop through all members on the hub and find client hub functions to subscribe/unsubscribe
for (memberKey in hub.client) {
if (hub.client.hasOwnProperty(memberKey)) {
memberValue = hub.client[memberKey];
if (!$.isFunction(memberValue)) {
// Not a client hub function
continue;
}
subscriptionMethod.call(hub, memberKey, makeProxyCallback(hub, memberValue));
}
}
}
}
}
$.hubConnection.prototype.createHubProxies = function () {
var proxies = {};
this.starting(function () {
// Register the hub proxies as subscribed
// (instance, shouldSubscribe)
registerHubProxies(proxies, true);
this._registerSubscribedHubs();
}).disconnected(function () {
// Unsubscribe all hub proxies when we "disconnect". This is to ensure that we do not re-add functional call backs.
// (instance, shouldSubscribe)
registerHubProxies(proxies, false);
});
proxies['signalRHub'] = this.createHubProxy('signalRHub');
proxies['signalRHub'].client = { };
proxies['signalRHub'].server = {
register: function () {
return proxies['signalRHub'].invoke.apply(proxies['signalRHub'], $.merge(["Register"], $.makeArray(arguments)));
},
setHiCalMode: function (mode) {
return proxies['signalRHub'].invoke.apply(proxies['signalRHub'], $.merge(["SetHiCalMode"], $.makeArray(arguments)));
}
};
return proxies;
};
signalR.hub = $.hubConnection("/signalr", { useDefaultPath: false });
$.extend(signalR, signalR.hub.createHubProxies());
}(window.jQuery, window));
我根据文档引用它,转换后的扩展名在 Chrome 中仍然有效。
以下是我在扩展程序中设置连接的方式:
$.connection.hub.url = 'http://localhost:9562/signalr';
$.connection.hub.start().done(init);
signalrHubProxy = $.connection.signalRHub;
我猜您尝试移植的扩展正在使用 NativeMessaging。如果是,根据 Edge 的扩展策略,扩展将无法直接与 Win32 应用程序通信。您需要将 Win32 应用程序转换为桌面新娘,同时使用无头 UWP 应用程序作为中间件来传达来自扩展程序和 Win32 应用程序的消息。
您可以在这里进一步阅读:
澄清一下,这个问题是关于基于 Chromium 之前版本的 Edge。 我正在尝试将 Chrome 扩展转换为 Edge 扩展,并使用 Microsoft Edge 扩展工具包进行了转换。该扩展在一个简单的 Windows 表单应用程序中连接到本地 SignalR 集线器 运行,以将消息从 Web 应用程序来回传递到外部连接的设备。我在尝试连接时从 SignalR 收到此错误:
Error: SignalR: Error loading hubs. Ensure your hubs reference is correct, e.g. script src='/signalr/js'>/script>.
我发现它位于 SignalR jquery 文件中,并且上面有一条注释说当正确引用集线器时错误消息将被替换。我可以导航到 localhost:9562/signalr/hubs 并从中心查看以下代码。
/*!
* ASP.NET SignalR JavaScript Library v2.2.2
* http://signalr.net/
*
* Copyright (c) .NET Foundation. All rights reserved.
* Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
*
*/
/// <reference path="..\..\SignalR.Client.JS\Scripts\jquery-1.6.4.js" />
/// <reference path="jquery.signalR.js" />
(function ($, window, undefined) {
/// <param name="$" type="jQuery" />
"use strict";
if (typeof ($.signalR) !== "function") {
throw new Error("SignalR: SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/js.");
}
var signalR = $.signalR;
function makeProxyCallback(hub, callback) {
return function () {
// Call the client hub method
callback.apply(hub, $.makeArray(arguments));
};
}
function registerHubProxies(instance, shouldSubscribe) {
var key, hub, memberKey, memberValue, subscriptionMethod;
for (key in instance) {
if (instance.hasOwnProperty(key)) {
hub = instance[key];
if (!(hub.hubName)) {
// Not a client hub
continue;
}
if (shouldSubscribe) {
// We want to subscribe to the hub events
subscriptionMethod = hub.on;
} else {
// We want to unsubscribe from the hub events
subscriptionMethod = hub.off;
}
// Loop through all members on the hub and find client hub functions to subscribe/unsubscribe
for (memberKey in hub.client) {
if (hub.client.hasOwnProperty(memberKey)) {
memberValue = hub.client[memberKey];
if (!$.isFunction(memberValue)) {
// Not a client hub function
continue;
}
subscriptionMethod.call(hub, memberKey, makeProxyCallback(hub, memberValue));
}
}
}
}
}
$.hubConnection.prototype.createHubProxies = function () {
var proxies = {};
this.starting(function () {
// Register the hub proxies as subscribed
// (instance, shouldSubscribe)
registerHubProxies(proxies, true);
this._registerSubscribedHubs();
}).disconnected(function () {
// Unsubscribe all hub proxies when we "disconnect". This is to ensure that we do not re-add functional call backs.
// (instance, shouldSubscribe)
registerHubProxies(proxies, false);
});
proxies['signalRHub'] = this.createHubProxy('signalRHub');
proxies['signalRHub'].client = { };
proxies['signalRHub'].server = {
register: function () {
return proxies['signalRHub'].invoke.apply(proxies['signalRHub'], $.merge(["Register"], $.makeArray(arguments)));
},
setHiCalMode: function (mode) {
return proxies['signalRHub'].invoke.apply(proxies['signalRHub'], $.merge(["SetHiCalMode"], $.makeArray(arguments)));
}
};
return proxies;
};
signalR.hub = $.hubConnection("/signalr", { useDefaultPath: false });
$.extend(signalR, signalR.hub.createHubProxies());
}(window.jQuery, window));
我根据文档引用它,转换后的扩展名在 Chrome 中仍然有效。
以下是我在扩展程序中设置连接的方式:
$.connection.hub.url = 'http://localhost:9562/signalr';
$.connection.hub.start().done(init);
signalrHubProxy = $.connection.signalRHub;
我猜您尝试移植的扩展正在使用 NativeMessaging。如果是,根据 Edge 的扩展策略,扩展将无法直接与 Win32 应用程序通信。您需要将 Win32 应用程序转换为桌面新娘,同时使用无头 UWP 应用程序作为中间件来传达来自扩展程序和 Win32 应用程序的消息。
您可以在这里进一步阅读: