-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SyntaxError: Unexpected end of JSON input #833
Comments
Same for me. Never had this before.. my iframe code: <iframe id="playerded75a" width="100%" height="100%" src="https://player.vimeo.com/video/76979871?muted=0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture; fullscreen" style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;" data-ready="true"></iframe> |
Thanks for reporting this issue @Stefano1964 @tesar-tech. Could one of you share a CodePen or JSFiddle in which this issue is reproduced? |
@rkrishnan8594 the error show by downloading the script this way: later, on user request there is a call to a function, but later, the errors show just after the player.js is downloaded (ExtJS code to show videos, this work without any problem, it's in place now from roundabout 1 year):
i also tested on Edge, same problem, so it's not related to Chrome |
The problem is that the player api is trying to JSON.parse inside an event listener for The player logic needs to verify the origin and e.data element before attempting to parse it as JSON. What happens is your library is trying to parse undefined when another library or the site itself uses postMessage for other purposes. You can reproduce the problem by calling You can fix the problem by changing the if block in the second listener in the compiled player:
to something like this:
Which will first verify the origin, but also default e.data to an empty array in the event that you have other bugs upstream. |
@agilemarcus so you are telling me that another library that i use is sending a post message? It's possible, i use a lot of library, but the problem come out recently. |
@Stefano1964 yeah it's in your stack trace above...
Whatever ViewSDKInterface.js is (looks like an adobe lib) it's first checking for the ability to use postMessage, and then it's sending one out, which is then being intercepted by the vimeo player. (I'm not sure why the I'm working on a patch for this today because we use a lot of postMessage calls in our app and this is filling up our logs with a tremendous amount of noise. I'll post it here later as a temporary workaround until the player api is patched and pushed to production. Until then, you could also just add this to your codebase:
...at the risk of losing some legitimate logging info if you rely on console.warn in your codebase. The good news is that this isn't actually an error being thrown in your application as the player api catches the error and just warns about it in the console. |
We're working on a fix for this error, but that's unlikely to be published until next week. |
Here's the patch I ended up writing - I feel pretty confident that the rudimentary string detection will pickup just the faulty callback in the player api and nothing else. You just need to define it in a script block that is loaded before the import for the vimeo player.js source. /**
* Patch window.addEventListener to work around JSON.parse in the
* vimeo player api.
* @ref: <https://github.com/vimeo/player.js/issues/833>
* @license: public domain
*/
const originalAEL = window.addEventListener;
window.addEventListener = function(type, listener, options) {
// Get the source code of the listener function
const source = listener.toString();
// The handler we care about has a couple strings that should
// uniquely detect the problematic code.
if (
type == "message" &&
source.includes('player\\.vimeo\\.com\\/video') &&
source.includes('appendVideoMetadata')
) {
// return a custom handler the first checks the origin
// before trying to parse JSON
return originalAEL(type, function(e) {
if ((e.origin || "").includes("https://player.vimeo.com")) {
listener(e);
}
}, options);
}
// Otherwise just use the original addEventListener
return originalAEL(type, listener, options);
}; |
@agilemarcus this make sense, i use an adobe sdk library for displaying pdf doc (https://documentcloud.adobe.com/view-sdk/main.js), thanks a lot for the explanation and yes i did not see that it was just in the stack trace |
Expected Behavior
No errors in console
Actual Behavior
player.js:2 SyntaxError: Unexpected end of JSON input
at JSON.parse ()
at E (player.js:2:6653)
at player.js:2:20089
E @ player.js:2
(anonymous) @ player.js:2
postMessage (async)
canUsePostMessage @ ViewSDKInterface.js:1
(anonymous) @ ViewSDKInterface.js:1
(anonymous) @ ViewSDKInterface.js:1
YBdB @ ViewSDKInterface.js:1
webpack_require @ ViewSDKInterface.js:1
(anonymous) @ ViewSDKInterface.js:1
URgk @ ViewSDKInterface.js:1
webpack_require @ ViewSDKInterface.js:1
B/eG @ ViewSDKInterface.js:1
webpack_require @ ViewSDKInterface.js:1
(anonymous) @ ViewSDKInterface.js:1
aE5D @ ViewSDKInterface.js:1
webpack_require @ ViewSDKInterface.js:1
Vu6y @ ViewSDKInterface.js:1
webpack_require @ ViewSDKInterface.js:1
window.adobe_dc_view_sdk.+Nns @ ViewSDKInterface.js:1
(anonymous) @ ViewSDKInterface.js:1
Steps to Reproduce
the error show after the script is loaded, just loaded, i dont setup anything about vimeo player at this time
if then i setup the player with config, etc, the videos are showing without any problems and no error in console
in the past i never see this error
Chrome version 102.0.5005.115
player.js version v2.17.0 loaded from here https://player.vimeo.com/api/player.js
anyway you have problem in your code if you dont check if json is valid...
The text was updated successfully, but these errors were encountered: