bind polyfill for PhantomJS
Asked Answered
P

1

3

I am trying to add bind polyfill in my phantomjs file using es5-shim.js.

I have tried to include es5-shim.js using require(), but I am still getting error when I execute the phantomjs file. What is the correct way to use this?

Ptisan answered 14/6, 2014 at 21:9 Comment(2)
Check this thread there are few suggestions on polyfills you can use to handle it.Serialize
I required it simply with require('./lib/es5-shim.js'); and it worked for me. The shim I used can be found hereSusette
E
1

I tried the polyfill in this link and it seems to work fine for me.

Note that phantomjs scripts run inside WebKit's JavaScriptCore engine (which uses ES5) so most of these functions should already come out of the box.

D:\>phantomjs.exe

phantomjs> console.log(Object.keys)
function keys() {
    [native code]
}
undefined

phantomjs> var shim = require("D:\\es5-shim.js");
undefined

phantomjs> console.log(Object.keys)
function keys(object) {
        if (isArguments(object)) {
            return originalKeys(ArrayPrototype.slice.call(object));
        } else {
            return originalKeys(object);
        }
    }
Ergo answered 27/6, 2014 at 1:5 Comment(5)
Thanks for pointing me to the link of that shim! You're an absolute live safer!Susette
hey @steven, or anyone: i'm implementing phantomJS through selenium webdriver with python bindings. how can i add this shim so that it will be included for the entire session of my PJS webriver instance? my webdriver instance does not have a "require" method, and it's tough to google it :-). this does not seem to merit a new SO question, but it's frustrating to me that i'm so close to solving this problem but can't seem to implement the solution.Bustee
I'm not familiar enough with GhostDriver but my guess is that since this running the webdriver protocol designed by Selenium (well before PhantomJS), there is no interaction with PhantomJS embedded JavaScriptCore engine and all commands go straight to the Webkit instance acting as the browser.Ergo
i think i follow, but it's still not clear to me how/where i insert the shim. please help.Bustee
I'm basically saying you cant unless you use PhantomJS directly via the command line.Ergo

© 2022 - 2024 — McMap. All rights reserved.