googleads / videojs-ima

IMA SDK Plugin for Video.js
Apache License 2.0
450 stars 284 forks source link

Getting "player.ima is not a function" #1073

Closed yashraj-02 closed 1 year ago

yashraj-02 commented 1 year ago
image

I am getting the player.ima is not a function error. Basically, I have added try catch to the entire function & the catch block is helping me to log the messages to my logging service.

My guess is that the function[new ImaPlugin(this, options);] is not getting attached [to the player.ima] till the time I call player.ima(options)

image

Callstack

TypeError: player.ima is not a function
    at setUpVideoJS (https://cdm.xyz.com/video.js:6093:10)
    at setupPlayer (https://cdm.xyz.com/video.js:6028:16)
    at insertPlayer (https://cdm.xyz.com/video.js:6016:10)
    at Object.bootstrap (https://cdm.xyz.com/video.js:6007:10)
    at https://cdm.xyz.com/42547/xyz.js:21:361824
    at video.cmd.push (https://cdm.xyz.com/video.js:75196:5)
    at https://cdm.xyz.com/42547/xyz.js:21:361783
    at u.push (https://cdm.xyz.com/prebid/pb.42547.1664965310891.js:4:416)
    at r (https://cdm.xyz.com/42547/xyz.js:21:361432)
    at e (https://cdm.xyz.com/42547/xyz.js:21:362404)
yashraj-02 commented 1 year ago

Anyone?

dioramayuanito commented 1 year ago

https://github.com/googleads/videojs-ima

    <!-- Load dependent scripts -->
    <script src="/path/to/video.js"></script>
    <script src="//imasdk.googleapis.com/js/sdkloader/ima3.js"></script>
    <script src="/path/to/videojs-contrib-ads.js"></script>
    <script src="/path/to/videojs.ima.js"></script>

maybe ima3.js is missing from your script?

yashraj-02 commented 1 year ago
image

Nope. It is present.

yashraj-02 commented 1 year ago

@dioramayuanito

Kiro705 commented 1 year ago

Hello @yashraj-02 ,

Would it be possible to reproduce this error using the plugin's sample apps?

Depending on where the try/catch is implemented, player.ima() may not be available.

Thank you, Jackson IMA SDK team

yashraj-02 commented 1 year ago

That’s the problem. The error is not reproducible on my side either. I am seeing this in error logs sent from client side from the actual users.

dioramayuanito commented 1 year ago

That’s the problem. The error is not reproducible on my side either. I am seeing this in error logs sent from client side from the actual users.

I have a feeling that your users "maybe" enabled an Ad Blocker

yashraj-02 commented 1 year ago

@dioramayuanito

script_1: core script

script_2: has videojs & videojs-ima code

Nice guess but that's not the case either. Because the core script (#script_1) gets blocked if an ad-blocker is present on the page. So the #script_2 never gets called.

yashraj-02 commented 1 year ago

@Kiro705 @dioramayuanito

gschoppe commented 1 year ago

the core script (#script_1) gets blocked if an ad-blocker is present on the page.

It is important to keep in mind that many different ad blockers exist, and may have completely different blocklists or fingerprints that they use to block certain resources. Just because one ad blocker prevents your #script_1 from loading does not mean that all will behave the same.

That said, player.ima is first instantiated by the call on line #3778 of videojs-ima.js.

The operations that need to occur for player.ima to exist are as follows:

If those conditions are all met, player.ima() will exist. On first call, it will create an instance of the ImaPlugin class. On subsequent calls, it will return the existing instance of ImaPlugin. This "singleton-esque" behavior is what is occurring in the Init function that you mentioned in your first post.

I would recommend testing your base assumptions by adding explicit logging code to verify each of the prerequisites that I listed above. I'd be willing to bet that for users who cannot access player.ima, at least one of those bullets is false.

Thanks,

Greg Schoppe IMA SDK Team

yashraj-02 commented 1 year ago

Thanks.

Also, I raised this in videojs forum also. They recommended me to rearrange the imports this way. video.js first, then contrib-ads, then ima

Currently, my imports are organized in this manner

image

Do you have any take on this?

Link to slack thread: https://videojs.slack.com/archives/C43LGP955/p1672309629213189?thread_ts=1672124949.828749&cid=C43LGP955

gschoppe commented 1 year ago

You definitely should reorder your imports, as they described, so as to match the order shown in the videojs-ima README file.

import videojs from 'video.js';
import 'videojs-contrib-ads';
import 'videojs-ima';

Thanks,

Greg Schoppe IMA SDK Team

yashraj-02 commented 1 year ago

Thanks @gschoppe. I am implementing this changes. I will update you guys here after we have the data in few days.

yashraj-02 commented 1 year ago

Do you guys have any idea regarding why does player.ima gets converted into an object later? Like, initially it's a function but after a few milliseconds, it gets converted to an object.

image image
dioramayuanito commented 1 year ago

do you initialize videojs-ima more than once? for multiple player?

yashraj-02 commented 1 year ago

Yup, I did that.

gschoppe commented 1 year ago

Do you guys have any idea regarding why does player.ima gets converted into an object later? Like, initially it's a function but after a few milliseconds, it gets converted to an object.

This is standard behavior for videojs plugins. You can read more about it in the videojs documentation.

Thanks,

Greg Schoppe IMA SDK Team