[英]phantomjs: how to run script with object.assign function?
I try to run phantomjs script for website that inculde js with Object.assign function and get an error: 我尝试为使用Object.assign函数植入js的网站运行phantomjs脚本,并收到错误消息:
TypeError:: undefined is not a function (evaluating 'Object.assign')
. TypeError:: undefined is not a function (evaluating 'Object.assign')
。
As i understand, phantomjs doesn't use ES-2015. 据我了解,phantomjs不使用ES-2015。 So i need to use polyfill like this .
所以我需要像这样使用polyfill。 I tried to make it work with injectJs, includeJs or even require with absolute url, but it still doesn't work.
我试图使其与injectJs,includeJs一起使用,甚至要求使用绝对URL,但仍然无法正常工作。
How to import this js and run script? 如何导入此js并运行脚本?
The problem could be that the webpage running Object.assign in a child frame. 问题可能是运行Object.assign的网页在子框架中。 If so, you have to use a polyfill in that frame.
如果是这样,则必须在该框架中使用polyfill。 You can use the following PhantomJS expression to print frame names on the page:
您可以使用以下PhantomJS表达式在页面上打印框架名称:
console.log('Current frames: ' + JSON.stringify(page.childFramesName()));
If so, you could inject polyfill in every frame: 如果是这样,您可以在每个帧中注入polyfill:
page.injectJs('polyfills.js');
page.childFramesName().forEach(function(childFrameName) {
page.switchToFrame(childFrameName);
page.injectJs('polyfills.js');
page.switchToMainFrame();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.