phantasma icon indicating copy to clipboard operation
phantasma copied to clipboard

trouble with once

Open skaplun opened this issue 10 years ago • 2 comments

Hey, So i've been playing with this for two days, running into issues with once. The basic idea i'm trying to achieve is to detect a redirect on page load and exit out of the flow. When i put once after open i get: TypeError: Cannot read property 'render' of null When i put once at the end of the chain i get: TimeoutError: operation timed out

                 return pha
                        .viewport(1360, 960)
                        .open('http://' + link[0] + link[1])
                        .once('onLoadFinished', function(status) {
                            if(status === 301){
                                console.log('redirect')
                                reject();
                            }
                            resolve();

                        })
                        .screenshot(cleanSlashes + '.png')
                        .catch(function (e) {
                            console.log('error in scrapurl', e)
                        })
                        .finally(function () {
                            pha.exit();
                            console.log('finally! single url');

                        });

skaplun avatar Jan 21 '16 06:01 skaplun

Have you tried calling .once before .open? I think you need to be listening for onUrlChanged instead, I'm not sure but onLoadFinished might only be called once the final page has loaded. Alternatively you could get the URL of the final page and check if it differs from the URL you specified.

petecoop avatar Jan 21 '16 11:01 petecoop

when i do that i get another error : node : Unhandled rejection TypeError: expecting an array, a promise or a thenable At line:1 char:1

skaplun avatar Jan 21 '16 11:01 skaplun