Skip to content

Commit 86c6e0c

Browse files
committed
Prevent setTimeout from firing if we can't match devtools user agent
1 parent 4bb6df7 commit 86c6e0c

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

src/core/ApolloClient.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,33 +1169,34 @@ export class ApolloClient {
11691169
*/
11701170
if (!hasSuggestedDevtools && __DEV__) {
11711171
hasSuggestedDevtools = true;
1172+
1173+
const ua = window.navigator.userAgent;
1174+
let url: string | undefined;
1175+
1176+
if (typeof ua === "string") {
1177+
if (ua.indexOf("Chrome/") > -1) {
1178+
url =
1179+
"https://chrome.google.com/webstore/detail/" +
1180+
"apollo-client-developer-t/jdkknkkbebbapilgoeccciglkfbmbnfm";
1181+
} else if (ua.indexOf("Firefox/") > -1) {
1182+
url =
1183+
"https://addons.mozilla.org/en-US/firefox/addon/apollo-developer-tools/";
1184+
}
1185+
}
1186+
11721187
if (
11731188
window.document &&
11741189
window.top === window.self &&
1175-
/^(https?|file):$/.test(window.location.protocol)
1190+
/^(https?|file):$/.test(window.location.protocol) &&
1191+
url
11761192
) {
11771193
setTimeout(() => {
11781194
if (!(window as any).__APOLLO_DEVTOOLS_GLOBAL_HOOK__) {
1179-
const nav = window.navigator;
1180-
const ua = nav && nav.userAgent;
1181-
let url: string | undefined;
1182-
if (typeof ua === "string") {
1183-
if (ua.indexOf("Chrome/") > -1) {
1184-
url =
1185-
"https://chrome.google.com/webstore/detail/" +
1186-
"apollo-client-developer-t/jdkknkkbebbapilgoeccciglkfbmbnfm";
1187-
} else if (ua.indexOf("Firefox/") > -1) {
1188-
url =
1189-
"https://addons.mozilla.org/en-US/firefox/addon/apollo-developer-tools/";
1190-
}
1191-
}
1192-
if (url) {
1193-
invariant.log(
1194-
"Download the Apollo DevTools for a better development " +
1195-
"experience: %s",
1196-
url
1197-
);
1198-
}
1195+
invariant.log(
1196+
"Download the Apollo DevTools for a better development " +
1197+
"experience: %s",
1198+
url
1199+
);
11991200
}
12001201
}, 10000);
12011202
}

0 commit comments

Comments
 (0)