Viewerready Event in Firefox


(Flbar) #1

I'm having a problem today with the viewer api. The viewerready event doesn't fire after the model starts in Firefox. It fires in Chrome and Edge still. Any thoughts?


Website Change Log
(Flbar) #2

Got the viewerready to fire once in Firefox, but then the problem resumed.


(Flbar) #3

Ok, The problem seems to be related to calls to the API's listenServer function. While this function fires for the viewerready event in Chrome and Edge, it doesn't in Firefox. Any thoughts?


#4

We're aware of an issue with viewerready in Firefox, but we have not been able to reproduce it consistently. Can you share your code?


(Flbar) #6

Here's some sanitized code. Mostly just boilerplate pulled from the body. It worked once in Firefox, but never again.

        <div>
            <div id="sketchfab-embed-wrapper" style="width:500px;height:500px;">
                <iframe id="model-iframe" frameborder="0" style="height:100%;width:100%;display:block;"></iframe>
            </div>
               
            <div id="hidden-div" style="display:none; text-align:center;width:500px;">
                <h2>This should appear after viewerready</h2>
                <p>Works in Chrome and Edge</p>
            </div>
        </div>

        <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
        <script src="/js/sketchfab-viewer-1.0.0.js"></script>

        <script type="text/javascript">
                $(function () {

                    var iframe = $("#model-iframe")[0];
                    var version = "1.0.0";
                    var urlid = "64d0b7662b59417986e9d693624de97a";

                    var error = function () {
                        console.error("Error api Sketchfab !");
                    };

                    var success = function (api) {
                        api.start();
                        api.addEventListener('viewerready', function () {
                      
                            $('#hidden-div').show();
                        });
                    };

                    var client = new Sketchfab(version, iframe);

                    client.init(urlid, {
                        success: success,
                        error: error,
                        preload: 1,
                        autostart: 1,
                        ui_stop: 0,
                        ui_vr: 0,
                        ui_fullscreen: 0,
                        ui_settings: 0,
                        ui_animations: 0,
                        ui_infos: 0,
                        autospin: 0,
                        camera:0
                    });

            });
        </script>

(Lpdenmark) #7

It seems to mee there is also some problems
with this in Chrome,

I´ll have to figure out when it happens, it´s
not every time, strange.

Hope we can point out exactly what
curse the problem.


(Klaasnienhuis) #8

We're having the exact same problem in firefox. We've isolated it to a hidden iframe. When we initialize the client while the iframe is hidden, the viewerready event is not triggered.
Like so

<!DOCTYPE HTML>
<html>
<head>
    <script type="text/javascript" src="https://static.sketchfab.com/api/sketchfab-viewer-1.0.0.js"></script>
</head>

<body>
    <!-- Insert an empty iframe, hidden by default-->
    <iframe src="" id="api-frame" allowfullscreen mozallowfullscreen="true" webkitallowfullscreen="true" style="display:none"></iframe>
    
    <!-- Initialize the viewer -->
    <script type="text/javascript">
        var iframe = document.getElementById( 'api-frame' );
        var version = '1.0.0';
        var urlid = '731235038f6945d19f10d9331b78ea09';
        var client = null;

        function loadmodel(){
            var client = new Sketchfab( version, iframe );
            client.init( urlid, {
                success: function onSuccess( api ){
                    console.log( 'Success' );
                    api.load();
                    api.start();
                    api.addEventListener( 'viewerready', function() {
                        console.log( 'Viewer is ready');
                        document.getElementById("api-frame").style.display = "block"; //once the viewer is ready, show the iframe
                    } );
                },
                error: function onError(callback){
                    console.log(this.error);
                }
            } );
        };
    </script>
    
     <button onclick="loadmodel()">Click me to load model and show iframe</button> 
</body>
</html>

This example works in chrome but not ff. If you set the initial display:none to display:block or just remove the display style entirely, it works in ff too.

@flbar if I set autostart to 0 in your example, viewerready is actually triggered. @james this is another lead!


(Lpdenmark) #9

will there be a fix for this?

The problem also occur in Chrome, and strange enough it´s not
static, sometimes it works and often it doesn´t.

Hope the error can be tracked and fixed :slight_smile:


(Madalin Berechet) #10

Same issue: "Viewer ready" event not detected on various webpages using Firefox and Sketchfab Viewer API.
Function I'm using to load the viewer: on Fiddle.
And Firefox console screen capture.


Also an error is detected:

XML read error: root element not found
Location: https://sketchfab.com/i/models/8d6a45bba32d458aa453cbd499b35869/views
Line number 1, column 1:


(Klaasnienhuis) #11

Hi @james, did you have any success replicating the issue with the example code and workaround provided here?


(Lpdenmark) #12

As mentioned in another note, the problem also exist
in Chrome, and in safari on Ipad & Iphone.


(Madalin Berechet) #13

@klaasnienhuis, thanks for autostart: 0 It's working.


#14

Sorry for the delay. We're working on it.


(Lpdenmark) #15

Nice :slight_smile:


(Lpdenmark) #16

Do you have an estimate for when this problem will be solved?

It´s going down the stack in the forum, so I post to hopefully
have an estimate and to move the topic up the stack :slight_smile:


#17

The fix is coming in our next release, probably tomorrow.


(Lpdenmark) #18

Thanks James, good news :slight_smile:


(Klaasnienhuis) #19

@james, I see in the update notice the viewerready event has been addressed. I'm not seeing any changes though. I've cleared my cache to avoid using a cached version of the sketchfab API. But for me the viewerready event does not fire.


(Lpdenmark) #20

To bad to hear klaasnienhuis.

The problem I had in Chrome seem to be solved by the update,
I don´t know what the problem was, but until today the viewerready
gave problems for us in Chrome browser, now it works alright.


(Lpdenmark) #21

I thing I was a little to fast to announce the problem has been solved,
it seems it is still not stable working.