Skip to content

Commit 1362648

Browse files
lideljscissr
authored andcommitted
fix: feature detection for Google Chrome
Old version did not check if chrome.sockets.* actually exist. This caused problems with extensions built for Chromium-based browsers that tried to maintain the single codebase and do feature-detection at runtime. License: MIT Signed-off-by: Marcin Rataj <[email protected]>
1 parent 93e340d commit 1362648

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ var servers = {}
2323
var sockets = {}
2424

2525
// Thorough check for Chrome App since both Edge and Chrome implement dummy chrome object
26-
if (typeof chrome === 'object' && typeof chrome.runtime === 'object' && typeof chrome.runtime.id === 'string') {
26+
if (
27+
typeof chrome === 'object' &&
28+
typeof chrome.runtime === 'object' &&
29+
typeof chrome.runtime.id === 'string' &&
30+
typeof chrome.sockets === 'object' &&
31+
typeof chrome.sockets.tcpServer === 'object' &&
32+
typeof chrome.sockets.tcp === 'object'
33+
) {
2734
chrome.sockets.tcpServer.onAccept.addListener(onAccept)
2835
chrome.sockets.tcpServer.onAcceptError.addListener(onAcceptError)
2936
chrome.sockets.tcp.onReceive.addListener(onReceive)

0 commit comments

Comments
 (0)