getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.85k stars 1.55k forks source link

undefined is not an object (evaluating 'window.webkit.messageHandlers') #3040

Closed ungarson closed 2 years ago

ungarson commented 3 years ago

One of my clients received this error: undefined is not an object (evaluating 'window.webkit.messageHandlers')

It seems to be thrown somewhere here:

Screenshot 2020-11-09 at 16 38 08

According to the breadcrums the error was thrown right before sending data to yandex analytics webvisor. I guess, it might be the reason, but I am not sure.

Screenshot 2020-11-09 at 16 47 24

I use sentry 5.27.2. It's not the newest, but it seems that 5.27.3 has nothing to do with the problem I described. If possible, let me know how I can prevent it, thanks 😇

JSON of the error: [Uploading sentry_json_review.zip…]()

Link: https://sentry.io/share/issue/2d981382a8a142ac8cd93a50e1ef8b62/

ungarson commented 3 years ago

Closed, since I didn't find a way to reproduce it.

evolvedlight commented 3 years ago

Hi, just FYI we're getting this lots suddenly now. It's only from iPhone Safari users.

image

It's from 3 different IP addresses, and I haven't yet been able to work out any reproduction myself, even though I have the same version

padinko commented 3 years ago

in our project too.. 1200 this errors a day.. i checked some user agents and all was a Edge for iOS

ungarson commented 3 years ago

Just in case anyone finds a way to reproduce, let us know ✊🏻

padinko commented 3 years ago

just opening next html in edge for iOS will create this issue

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<button type="button">test</button>
<script
        src="https://browser.sentry-cdn.com/6.2.2/bundle.min.js"
        integrity="sha384-SEu4bJkpht31dkOz4nRcKDxnisSU+Jc8WRSOnBSZJ2yVMlbk4sAKQSrBw6qBVzKR"
        crossorigin="anonymous"
></script>
<script>
Sentry.init({
    dsn: '__INSERT_DSN_URL__',
    release: '0.0.1',
});
document.querySelector('button').addEventListener('click', (event) => {
    event.preventDefault();
    alert(':)');
    banana();
});
</script>
</body>
</html>
bendavis78 commented 3 years ago

Can also confirm. Getting this error for Chrome Mobile on iOS.

andrewisaburden commented 3 years ago

Also getting this.

Mobile Safari Version: 14.0 iOS Version: 14.4 iPad

Sentry Version: 6.1.0

thhermansen commented 3 years ago

We do also get this. Seems to be present for our mobile app.

SDK: 6.2.2

ungarson commented 3 years ago

@rbisol status can be changed I guess, reproduction is described 4 comments above

kamilogorek commented 3 years ago

@padinko I tried to use your exact repro with no luck ¯_(ツ)_/¯ I was only able to break it using the button, which produces regular reference error, but never the one from the original post.

image

image

image

iOS 14.4.1
Edge 46.2.0

Tried on Chrome and Safari with no luck as well.

padinko commented 3 years ago

I tried it right now and still have problem: image

iOS: 14.4 Edge: 46.2.0

I am updating iOS to 14.4.1 to see if it helps (will edit this post soon) or maybe it's some settings? i have strict tracking protection and 3rd party cookies blocking and adblock installed and enabled

update: iOS 14.4.1 same problem - you need only load page, do not need to click button to this exception i tried turn off tracking protection, allow all cookies, disable (uninstall) adblock.. and still issue is creating

update 2: Edge 46.2.5 still issue exists Edge 46.3.5 same

padinko commented 3 years ago

maybe I got it: i tried it on my iPad with iPadOS 14.4.1.. clean install Edge and no error then i try to move all setings from my iPhone in edge 1by1 and refreshing and it seems changing search engine to Google, then kill and reopen edge, then open this page cause a problem.. so probably this is edge issue?

ShirleyLii commented 3 years ago

Having the same error when I was trying to listen the post message with WKWebview

janantala commented 3 years ago

I have got the same error:

Mac OS X Version:10.12.4
Safari Version:10.1
lepouletsuisse commented 3 years ago

I have the same issue with users using Safari on their Ipad:

Mobile Safari 14.0
iOS 14.5.1

And the exact User-agent if it can help:

Mozilla/5.0 (iPad; CPU OS 14_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 EdgiOS/46.3.13 Mobile/15E148 Safari/605.1.15
nicubarbaros commented 3 years ago

We got the same errors.

User agent


Mozilla/5.0 (iPhone; CPU iPhone OS 14_4_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 EdgiOS/46.2.5 Mobile/15E148 Safari/605.1.15
--
Vetrano89 commented 3 years ago

We've run into the same issue, 5 users all on iOS Chrome:

Mozilla/5.0 (iPhone; CPU iPhone OS 14_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/90.0.4430.216 Mobile/15E148 Safari/604.1
igoradamenko commented 3 years ago

We're getting these errors from custom iOS browsers, e.g.:

Mozilla/5.0 (iPhone; CPU iPhone OS 14_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 YaBrowser/21.3.3.1242.10 SA/3 Mobile/15E148 Safari/604.1
zhdanouskikh commented 3 years ago

Any updates on this? The issue was created in November(

v7 commented 3 years ago

I think I will add this to my ignored errors because this seems to be so random and not easy to reproduce.

trungvose commented 3 years ago

Seems it only happens on the mobile device. We received tons of this error on our web app and most of the issues coming from mobile browser. I am not sure how to reproduce it...

image

dimaqq commented 3 years ago

@ungarson perhaps it's time to consider reopening this issue? Edit: I was blind, it got closed and re-opened soon after.

looks like our customers also managed to hit this, with (Microsoft) Edge for iOS: Mozilla/5.0 (iPad; CPU OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 EdgiOS/46.3.24 Mobile/15E148 Safari/605.1.15

uandco commented 3 years ago

Same here. First time I ever see it. Mozilla/5.0 (iPad; CPU OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 EdgiOS/46.3.24 Mobile/15E148 Safari/605.1.15

Using Sentry JS SDK 6.10.0

ungarson commented 3 years ago

@dimaqq the issue is actually open 😄 But... I'm not sure if the work on it is in progress

ZerdoX-x commented 3 years ago

So this is sentry's issue, am I right? I can't understand if it's any plugin or service errors.. I also get this annoying events on my web app, all of them are coming from iphone and ipad and safari browser. I get error like this:

TypeError: undefined is not an object (evaluating 'window.webkit.messageHandlers.selectedTextHandler.postMessage')
TypeError: undefined is not an object (evaluating 'window.webkit.messageHandlers')
TypeError: undefined is not an object (evaluating 'window.webkit.messageHandlers.bingLanguageDetectScriptResponse.postMessage')

Same users always reproduce this issues (i get 153 events from 19 users)

kevinpmcc commented 3 years ago

Adding that we have seen 10.4k events from 88 users. All Mobile Safari users. Error message is TypeError i(@sentry/browser/esm/helpers) undefined is not an object (evaluating 'window.webkit.messageHandlers.selectedTextHandler.postMessage')

kamilogorek commented 2 years ago

This error is happening because window.webkit is a non-standard namespace, which appears only in WKWebView environments. Whenever it's used within an app or website that can be accessed through other browsers, it should be preceded by other checks, see https://diamantidis.github.io/2020/02/02/two-way-communication-between-ios-wkwebview-and-web-page for a good snippet.

The reason why Sentry is reporting it, is that we are wrapping addEventListener API to provide additional data around the handler (like its name or arguments).

You can disable this integration with:

Sentry.init({
  integrations: [new Sentry.Integrations.TryCatch({
   eventTarget: false,
  })]
});

However, it will not fix the issue, as Sentry is not what's causing it. It will just be reporter "raw" when the above integration is disabled. If you don't want to update SDK initialization code to use beforeSend or ignoreErrors configuration, you can use Inbound Filters built into Sentry https://sentry.io/settings//projects//filters/data-filters/ and filter it by message.

ref: https://stackoverflow.com/questions/32771215/wkwebkit-javascript-on-loaded-page-finds-window-webkit-is-undefined ref: https://stackoverflow.com/questions/56899711/window-webkit-in-typescript ref: https://stackoverflow.com/questions/54745833/cannot-read-property-messagehandlers-of-undefined ref: https://stackoverflow.com/questions/34733678/script-message-handler-not-working

redtogin commented 1 year ago

@kamilogorek Could you please expand on the possible origin of the issue? So is it not Sentry code that tries to access window.webkit when it's not present?

Or is that access coming from 3rd party code in our web apps? We have a pure web app, it's only the users who open them in in-app browsers potentially on different devices that we can't control.

And given the example above with triggering the error in an isolated html with only sentry in it, I would assume that the error is indeed triggered by Sentry.

Could Sentry not do a check before accessing window.webkit? Or am I missing something? Thanks in advance.

kamilogorek commented 1 year ago

Could Sentry not do a check before accessing window.webkit? Or am I missing something? Thanks in advance.

The thing is that we are not accessing it directly. We are only wrapping native APIs, which are generic over all possible variants, and we're not able to pick which one should be verified and which one not. This issue is caused by the communication between different webviews/iframes/workers (or whatever else is using message api) that are somehow out of sync with their permissions/configurations (mostly due to mobile browser settings I assume). Other than filtering this issue, there's not much we can control here.

redtogin commented 1 year ago

@kamilogorek I see, thanks for the explanation!