sentry-javascript: undefined is not an object (evaluating 'window.webkit.messageHandlers')

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/

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 22
  • Comments: 30 (3 by maintainers)

Most upvoted comments

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>

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

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

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

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/<org>/projects/<project>/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

@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

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')

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)

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

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

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