0

I am using Embedly in React.js application to show URL preview in the page that has arrow navigation, and I am getting an error when switching page before embed content loaded.

The error message received is:

Uncaught TypeError: Cannot read property 'cards' of null
    at n.done (platform.js:7)
    at e.done (platform.js:8)
    at e.each (platform.js:8)
    at e.<anonymous> (platform.js:8)
    at n.<anonymous> (platform.js:7)
    at platform.js:7
    at Array.forEach (<anonymous>)
    at Object.e.each (platform.js:8)
    at platform.js:7
    at Array.forEach (<anonymous>)

Setting Chrome to pause on exceptions, and using its pretty print to make the code more easily readable, we see that the contentWindow property of parameter b is null, hence the error. However, this error is coming from the third party Platform.js, so I cannot amend that code myself to work around the issue there.

Screenshot of exception in Chrome

In order to recreate the issue, open this JS Fiddle. In the lower right pane you'll see the running example. Click the Next button several times very quickly, after a few attempts the error will appear in the console / Chrome will pause execution (if set to do so).

Question

Is there anything I can do in my own code to prevent this exception from occurring in platform.js?

JohnLBevan
  • 22,735
  • 13
  • 96
  • 178
aLLeXUs
  • 64
  • 1
  • 4
  • Can you share your related code & a link to the `platform.js` script that your script's using (so we can see what's on lines 7 & 8 / assuming it's available in source control or a CDN somewhere)? The issue is that the script is trying to access the `cards` property of an object, but that object is set to null; but that's all we can tell from the error message. – JohnLBevan Jul 12 '19 at 08:06
  • you should check for the existence of `cards` before using it. e.g. `var test = { cards: [] }; test.cards&& test.cards.push(somevalue)` – Harish Jul 12 '19 at 08:46
  • @JohnLBevan It is a script provided by Embedly https://docs.embed.ly/v1.0/docs/platformjs –  aLLeXUs Jul 12 '19 at 08:58
  • @Harish I can't change anything there, it's Embedly library –  aLLeXUs Jul 12 '19 at 08:59
  • Thanks @aLLeXUs; so are you using this copy of the file? http://cdn.embedly.com/widgets/platform.js (since distributions may differ / some people use minified versions whilst others use debuggable versions). Also, can you share your code that calls this library; as likely the library is OK but it's the data it's given that's causing this issue. – JohnLBevan Jul 12 '19 at 09:14
  • @JohnLBevan I've added additional information to the question. So I'm not parsing it directly. It's handled by the library. –  aLLeXUs Jul 12 '19 at 09:26
  • Can you create an minimal reproducible example (https://stackoverflow.com/help/minimal-reproducible-example)? i.e. This is all we have so far: https://jsfiddle.net/opt5ywxm/, and that's making a few assumptions. – JohnLBevan Jul 12 '19 at 09:36
  • 1
    @JohnLBevan Here is a [reproducible example](https://jsfiddle.net/aLLeXUs/b4kzvLeh/3/), just switch links fast, and you will see errors in the console –  aLLeXUs Jul 12 '19 at 11:18
  • Hmm, I can't recreate your issue - when you say "switch links" do you mean click "Next" several times quickly? Ps. What browser (including its version) are you using? – JohnLBevan Jul 12 '19 at 11:28
  • @JohnLBevan Yes, I mean to click "Next" or "Prev" button several times. Just try to click as fast as you can, but it depends on how fast your internet connection is, so you can try to slow down it. Browser - Google Chrome Version 74.0.3729.169 (Official Build) (64-bit). –  aLLeXUs Jul 12 '19 at 11:38
  • Thanks. I've been able to recreate your issue now, and have updated your question to include the additional info from your comments. I'd say it's worth reporting as a bug to Embedly, as it is an issue in their library / they could fix it more easily than you could work around it. The issue seems to be this one: https://stackoverflow.com/questions/12199797/why-is-iframe-contentwindow-null – JohnLBevan Jul 12 '19 at 12:17
  • 1
    @JohnLBevan thank you for your help, I'll report the issue to Embedly. –  aLLeXUs Jul 12 '19 at 12:24

0 Answers0