sdesalas / triflejs Goto Github PK
View Code? Open in Web Editor NEWHeadless automation for Internet Explorer
Home Page: http://triflejs.org/
License: MIT License
Headless automation for Internet Explorer
Home Page: http://triflejs.org/
License: MIT License
The following script runs fine in phantom but not in trifleJS. Returning normal string is fine, but returning an object isn't.
var page = require('webpage').create();
var url = 'http://www.google.com/';
page.open(url, function (status) {
var js = page.evaluate(function () {
return document;
});
console.log(JSON.stringify(js));
phantom.exit();
});
Setting the onInitialized function does not cause it to be called, as the check to call it is currently in the WebPage constructor (init function of WebPage.js).
run:
TrifleJS.exe onInitialized.js
onInitialized.js:
var page = webpage = require('webpage').create();
page.onInitialized = function() {
console.log('should log');
};
// any url
page.open('about:blank');
should log
The PhantomJS spec says (http://phantomjs.org/api/webpage/handler/on-initialized.html):
This callback is invoked after the web page is created but before a URL is loaded. The callback may be used to change global objects.
The logic should be moved into the open function. This is actually a bit trickier than it looks at first glance because the PhantomJS spec allows you to change global objects on the page, which the .NET client will clear on calls to navigate. A callback needs to be set up to invoke the supplied function at the proper time after creating the page.
Do you have plans to implement CasperJS API ?
See:
https://github.com/ariya/phantomjs/wiki/REPL#auto-completion
Tapping TAB (i.e. →|) can make all the difference:
phantomjs> phantom.→|
phantomjs> phantom.injectJs→|
phantomjs> phantom.exit→|
phantomjs> phantom.version→|
phantomjs> phantom.outputEncoding⏎
"UTF-8"
phantomjs>
We have tried selenium/webdriver + phantomjs, however, this solution can not handle popup windows, alerts well. I hope trifleJS can support selenium integration in the future
This cup is the logo of Java, as Java has nothing to do with Javascript.
C:\TrifleJS.Latest (1)>TrifleJS.exe -u
============================================
TrifleJS -- Unit Tests
============================================
(0,0): Object reference not set to an instance of an object.
bootstrap.js (82,29): Value cannot be null.
Parameter name: value
test/unit/tools.js (64,1): ReferenceError: console is not defined
Press any key to finish...
I'm running into this problem when trying to deploy on different servers. Sometimes I need to install .NET framework, sometimes I need to install some distributable. Since .NET is open sources with mono runtime, Is it feasible to include them so trifle doesn't have to depend on external dependencies?
Granted, the fragment entered in to page.content is not a full page of HTML. All the same, the response Error getting value from 'focusedFrameName' on 'TrifleJS.API.Modules.WebPage'.
lacks grace.
C:\Users\Bruce\Downloads\headless\Trifle>TrifleJS.exe
triflejs> var page = require('webpage').create();
null
triflejs> page
{
"uuid": "1986bc15",
"title": "",
"url": "about:blank",
"uri": "about:blank",
"content": "<HTML></HTML>\u0000",
"plainText": "",
"customHeaders": {},
"windowName": "",
"framesCount": 0,
"framesName": [],
"frameName": "",
"frameTitle": "",
"frameUrl": "about:blank",
"frameContent": "",
"framePlainText": "",
"focusedFrameName": "",
"canGoBack": false,
"canGoForward": false,
"loading": false,
"cookies": [],
"viewportSize": {
"width": 400,
"height": 300
},
"zoomFactor": 1.0,
"clipRect": {
"top": 0,
"left": 0,
"width": 0,
"height": 0
}
}
triflejs> page.content = "<h1>Hello</h1>"
<h1>Hello</h1>
triflejs> page.content
<h1>Hello</h1>
triflejs> page
(0,0): Error getting value from 'focusedFrameName' on 'TrifleJS.API.Modules.WebPage'.
Bruce/bugmagnet
Browser.DocumentCompleted event does not take remote resources (such as images) into account. It fires before these have finish loading.
Images hosted in the same server (domain presumably) load correctly, however those imported from other domains do not load.
TEST CODE
Note that when running the code below the TrifleJS logo will show up but the "Fork Me on Github" banner does not.
var page = require("webpage").create();
page.open("http://www.triflejs.org", function(status) {
if (status === 'success') {
page.render("triflejs.org.png");
}
phantom.exit();
});
SOCKS proxy does not seem to be working in IE8.
This could be something to do with underlying browser config. Need to try with IE9 to be certain.
Here is a SOCKS proxy that works with Firefox & Chrome (but not IE8):
http://www.softpedia.com/get/Internet/Servers/Proxy-Servers/FreeProxy.shtml
Hi, I notice trifle crashes from time to time with the error message Vector smash protection is enabled.
while scarping the web.
Not sure if it's related to flash or not, but it does crash on the official flash test page.
>TrifleJS --debug --render=http://www.adobe.com/software/flash/about/
Setting Version to IE11
Rendering https://www.adobe.com/software/flash/about/...
Vector smash protection is enabled.
>
The weird thing is it renders flash on other pages just fine. Tested both 0.4 and latest on 2 machines.
TrifleJS is using JSON.stringify() to copy objects from IE context to the V8 runtime where test scripts are executed. Thus if you do something like this:
page.onCallback = function(theDate, theType) {
console.log(theDate, theType);
}
page.evaluate(function(date) {
window.callPhantom(date, typeof date);
}, new Date());
You will recieve:
[
"2015-03-08T03:05:10.294Z",
"object"
]
Meaning that IE gets an object, but sends back a ISO date string.
Please investigate actual behaviour in PhantomJS and add some unit tests.
This may be related to VS2013 rather than trifle, but when I take a fresh checkout, open the solution in VS 2013, and run (in debug mode) TrifleJS.exe examples/countdown.js, I get the following error:
bootstrap.js (53,28): TypeError: Object #<Object> has no method 'SetInterval'
Trying to run TrifleJs from command line give me:
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembl
y 'Noesis.Javascript, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ae36d046c
7f89f85' or one of its dependencies. The application has failed to start because
its side-by-side configuration is incorrect. Please see the application event l
og or use the command-line sxstrace.exe tool for more detail. (Exception from HR
ESULT: 0x800736B1)
File name: 'Noesis.Javascript, Version=0.0.0.0, Culture=neutral, PublicKeyToken=
ae36d046c7f89f85' ---> System.Runtime.InteropServices.COMException (0x800736B1):
The application has failed to start because its side-by-side configuration is i
ncorrect. Please see the application event log or use the command-line sxstrace.
exe tool for more detail. (Exception from HRESULT: 0x800736B1)
at TrifleJS.Program.Interactive()
at TrifleJS.Program.Main(String[] args)
Event viewer gives me:
Activation context generation failed for "C:\TrifleJS\Noesis.Javascript.dll". Dependent Assembly Microsoft.VC90.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.30729.6161" could not be found. Please use sxstrace.exe for detailed diagnosis.
Is this because I am running on 64 bit? I should have all runtimes etc installed.
triflejs --version
prints out 1.7.0
while the version installed is 0.4
.
Hi,
how I can use trifleJS as engine for casperJs ?
I don't need a full support of API, Just a POC to work on it.
Thank You
Try this command:
TrifleJS.exe --render=https://www.zscaler.com/
There are Javascript error on the page. This creates 2 popups that need to be acknowledge manually. My Internet options have "Disable script debugging (Internet Explorer)" and "Disable script debugging (Other)" enabled, "Display a notification about every script error" disabled.
This might be enough to disable these warnings:
webBrowser.ScriptErrorsSuppressed = true;
Screenshots taken with the page.render() function don't reach the height they should.
I've tried with a couple different sites and for some reason render stops at either the viewport height (which seems logical on the surface but is not the behaviour of PhantomJS - it extends to the bottom of the page) or at 800px if I omit the height. I also get heights of 800px if I try to manually set the height as obtained from evaluating variants of this function:
var D = document;
var myHeight = Math.max(
D.body.scrollHeight, D.documentElement.scrollHeight,
D.body.offsetHeight, D.documentElement.offsetHeight,
D.body.clientHeight, D.documentElement.clientHeight
);
(from https://stackoverflow.com/questions/10173236/window-innerheight-ie8-alternative and various other places)
I tested the same function directly in the browser and it works to give page heights well over 800px.
Running the exe with these arguments:
\foo\foo\foo\foo\TrifleJS.exe \foo\foo\foo\foo\rasterize.js http://foo:123/foo/foo.html?foo=123 C:\foo\foo.png
When doing a loop thru system.args however, only returns this:
0: \foo\foo\foo\foo\rasterize.js
I expect this:
0: \foo\foo\foo\foo\rasterize.js
1: http://foo:123/foo/foo.html?foo=123
2: C:\foo\foo.png
Here is the command I'm running:
var system = require('system');
system.args.forEach(function(arg, i) {
console.log(i + ': ' + arg);
});
This is on beta 0.5
Hello, I'm a beginner on this and i'm trying to run trifleJs on Windows Server 2008 SP2,
here's my code;
C:> TrifleJS.exe --emulate=IE8 download_data.js
download_data.js :
var page1 = require('webpage').create(),
pag1 = 'http://10.192.XX.XX:8888/Ingenieria/logiN.do',
dat1 = 'user=myuser&pass=mypass';
page1.open(pag1, 'post', dat1);
page1.onLoadFinished = function(){
page1.evaluate(function(){
document.getElementById('frmPantalla').src='http://10.192.XX.XX:8888/Ingenieria/showScreen.do?action=doit';
document.getElementById('msj').style.display = "none";
document.getElementById('background').style.display = "none";
";
});
window.setTimeout(function () {
page1.render('./prueba.png');
phantom.exit();
}, 60000);
};
And i'm not getting anything.
Thanks in advance.
When the page is loaded, I set up a timeout (window.setTimeout). For timeout values of 3s or more, the timeout event never trigger.
With a window.setInterval set to 1s, it stop triggering after 2s.
The work around is to create a window.setTimeout every 1s or so.
Here is the output:
C:...\trifleJS\bin\Debug>TrifleJS.exe --debug --render=http://livedoor.com/
TrifleJS.exe --debug --render=http://livedoor.com/
Setting Version to IE11
Rendering http://livedoor.com/...
WebBrowser#DocumentCompleted
Render(,)...
Ratio: 1
Width: 1007
Height: 1045
Screenshot rendered to file: livedoor.com.png
WebBrowser#DocumentCompleted
Render(,)...
Ratio: 1
Width: 1007
Height: 1045
Screenshot rendered to file: livedoor.com.png
Then it hangs.
With more debugging, I caught this error message:
System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.
at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCD, IntPtr& ppTarget, Boolean& pfNeedsRelease)
at System.Windows.Forms.UnsafeNativeMethods.IHTMLWindow2.GetDocument()
at System.Windows.Forms.HtmlWindow.get_Document()
at TrifleJS.API.Modules.WebPage._evaluate(String function, Object[] args)
The excpetion happemns inside the check for CurrentFrame.Document != null
If you trap the exception inside _evaluate and wait long enough, the page will load completely and a screenshot can be taken.
I got this error:
WebPage.prototype.render(filename)
trifle.modules.WebPage.js (157,17): Parameter is not valid.
I'm not sure if (157,17) refers to the .Net source code or the javascript file TrifleJS. executes. Line 157 in WebPage.cs has no code. I looked for "Parameter is not valid" in the whole project, I could not find it.
when running a local html file i get
Error: 20
Permission Denied
when i run the following command
./Triflejs.exe --render=C:\git\inputmanager\InputManager.tests.jasmine\test-runner.html
Last download build not work
TrifleJS.exe --debug --emulate:IE8 test.js
Setting Version to IE9 <=== !!!
File does not exist: --emulate:IE8
TrifleJS.exe --debug --emulate:IE9 test.js
Setting Version to IE9
File does not exist: --emulate:IE9 <=== !!!
TrifleJS.exe --debug test.js
Setting Version to IE9
new System()
new FileSystem()
new WebPage()
WebPage.prototype.open()
new Callback#0a4956e7(func, scope, defaultArgs)
Opening http://127.0.0.1:81/eservice/build/index.html
Callback.executeOnce("0a4956e7", [args])
Callback.execute("0a4956e7", [args])
WebPage.prototype.evaluate(func)
WebPage.prototype.evaluate(func)
WebPage.prototype.evaluate(func)
window.setTimeout(callback, 100)
new Callback#32a3359f(func, scope, defaultArgs)
and nothing , no progression, i must kill cmd
If a download the old build (https://github.com/sdesalas/trifleJS/blob/587e6a0887d2dc8be9f6f525d257e4670058f63f/Build/Binary/TrifleJS.Latest.zip) all is ok
it doesn't support window.navigator.userAgent or page.settings.userAgent.
This error happens in interactive mode only, not when using he --render option:
TrifleJS.exe
Unhandled Exception: System.IO.FileLoadException: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
at TrifleJS.Program.Interactive()
at TrifleJS.Program.Main(String[] args) in c:...\trifleJS\Program.cs:line 88
I'm using Visual Studio 2013, the project was converted automatically. The .Net target for the solution is 4. I couldn't figure out which assembly has been compiled for .Net 2.
See example:
https://github.com/ariya/phantomjs/wiki/REPL
phantomjs> window.navigator⏎
{
"cookieEnabled": true,
"language": "en-GB",
"productSub": "20030107",
"product": "Gecko",
"appCodeName": "Mozilla",
"mimeTypes": {
"length": 0
},
"vendorSub": "",
"vendor": "Apple Computer, Inc.",
"platform": "MacIntel",
"appName": "Netscape",
"appVersion": "5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.6.0 (development) Safari/534.34",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.6.0 (development) Safari/534.34",
"plugins": {
"length": 0
},
"onLine": false
}
After calling page.open
, page.onCallback
doesn't trigger when window.callPhantom
is called. It works from a newly created page, but that's it.
test_onCallback.js
var webPage = require('webpage');
var page = webPage.create();
page.onCallback = function(data) {
console.log('CALLBACK: ' + JSON.stringify(data));
// Prints 'CALLBACK: { "hello": "world" }'
};
page.evaluate(function () {
callPhantom({ hello: 'world' });
});
page.open('about:blank', function (status) {
page.evaluate(function () {
callPhantom({hello : 'back'});
});
phantom.exit();
});
CALLBACK: {"hello":"world"}
CALLBACK: {"hello":"back"}
CALLBACK: {"hello":"world"}
Object doesn't support property or method 'xdebug'
Sometime between when the page is created, and a url is opened the ObjectForScripting becomes inaccessible in the window via external.
Currently when attempting to access a localhost https:// URL via render I get some nice dialog boxes, however, doing the same from within a script results in an instant "success" in the callback but no actual website is loaded. If this isn't something on your short term road map, do you have any pointers for next steps?
Thank you!
Hi,
Currently PhantomJS supports IPC using Websocket client.
Can TriffleJS also add support for WebSocket client in TriffleJS context? I would be more than happy to submit a PR if that makes sense.
This would be a really powerful tool to use in continuous integration environment. Do you have any plans to support non-windows platforms?
Have you planned the proxy settings --proxy
and --proxy-auth
as phantomjs (https://github.com/ariya/phantomjs/wiki/API-Reference) or slimerjs (http://docs.slimerjs.org / current / configuration.html)
thank you
Websites can open window popus. See the fix at juliensobrier@df345c5:
this.NewWindow += delegate(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true; ;
};
Microsoft open sourced .NET
Are there any plans to make this work for Mac?
STEPS TO REPRODUCE:
trifle.trifle = trifle
MORE INFO:
This issue actually occurs in the Noesis.Javascript.dll dependency, the parameter conversion from V8 to C# does not take infinite recursions into account.
POSSIBLE FIX:
Recurse over objects inside V8 and remove self-references before passing back to C#.
We have a web page which displays differently in webkit and trident (IE). However, trifleJS seems to show the webkit version than the trident version. Documentation say that trifleJS uses the trident layout engine. Example code follow:
var page = require('webpage').create();
page.open('sampleurl.html', function() {
page.render('test.png');
phantom.exit();
});
Hello,
I found an issue, I use trifleJS to capture a specific DOM element, the same code that can work correctly in Phantom, but in trifileJS can not work correctly.
This is my full code, and my IE=11
var page = require('webpage').create(),
system = require('system'),
address, output, size;
var output = "cnblog.png";
var address = "http://news.cnblogs.com/n/521792/";
page.viewportSize = { width: 1366, height: 768 };
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
phantom.exit();
} else {
window.setTimeout(function () {
var fk=page.evaluate(function () {
var response;
// var element = document.getElementById("news_main"); // script error, getBoundingClientRect not defined
var element = document.querySelector('#news_main'); // returns {}
//var element = document.documentElement // returns {}
var rect = element.getBoundingClientRect();
response = rect.height;
return '{"width":'+rect.width+',"height":'+rect.height+',"top":'+rect.top+',"left":'+rect.left+'}';
});
var clipRect = JSON.parse(fk);
page.clipRect = {
top: clipRect.top,
left: clipRect.left,
width: clipRect.width,
height: clipRect.height
};
console.log(page.clipRect)
page.render(output);
phantom.exit();
}, 1000);
}
});
Here are the results:
The correct one.
hello @sdesalas
This code works with previous build (last month), but not with last.
page.open("http://127.0.0.1768/build/index.html", function(status) {
if (status !== "success") { console.log("FAIL to load the address"); phantom.exit(); }
page.render('open1.png');
page.open("http://127.0.0.1768/build/solde.html", function(status) {
if (status !== "success") { console.log("FAIL to load the address"); phantom.exit(); }
page.render('open2.png');
phantom.exit(); // last open so exit
});
});
Is this a bug? How do I make multiple pages render?
Thank, Ami44
I can't get anything from this, returned value is an empty object. I saw one of your test case actually is calling getBoundingClientRect().
console.log(page.evaluate(function() {
var response;
var element = document.getElementById("ef");
// var element = document.documentElement; not working either
var rect = element.getBoundingClientRect();
response += rect.left;
return response;
}));
Any idea or suggestion on how do I debug this?
With this code, the viewport property has no effect when render. Render always returns in 1024 x 800.
var page = require('webpage').create();
page.viewportSize = { width: 300, height: 800 };
console.log(JSON.stringify(page.viewportSize));
page.open("http://www.phantomjs.org", function(status) {
if ( status === "success" ) {
page.render("render300x800.png")
phantom.exit();
}
});
Is it possible to set the size of screen capture?
Thank, AMi44
Hello @sdesalas
TrifleJS.Lastest.zip is older than one month
I do not have a development environment on my computer so I can not compile triflejs. So I can not use or test the latest commits.
I would be very grateful to automate the generation of https://github.com/sdesalas/trifleJS/blob/master/Build/Binary/TrifleJS.Latest.zip file.
Happy New Year
Thank you
Ami44
It seems a bit odd to use Chrome's JS engine instead of IE's one.
This one here claims to be able to embed Chakra:
https://github.com/Taritsyn/MsieJavaScriptEngine
MS itself seems to support officially Chakra only via IE11 :(
https://msdn.microsoft.com/en-us/library/dn249673%28v=vs.94%29.aspx
http://www.panopticoncentral.net/2013/07/02/introducing-jsrt-embedding-javascript-on-windows/
IMHO it would be great to use Chakra to be able to have a real test run for the browser as the JS engine is a vital part of the ahem browsing experience.
Cheers,
Masi
Hi guys,
Please let me know if I missed something, but I was typing in the command to emulate IE8, however the whatbrowser screenshot always shows that i'm currently using IE10.
TrifleJS.exe --debug --emulate=IE8 --render=http://whatbrowser.org/
Thanks!
Since these are set up on DocumentCompleted
, the page has already run it's JavaScript and they are not available until the onload
event has fired.
test_callPhantom.js
var page = require('webpage').create();
page.onCallback = function(data) {
console.log('CALLBACK: ' + JSON.stringify(data));
// Prints 'CALLBACK: { "hello": "world" }'
};
page.open('http://path/to/below/file', function(status) {
phantom.exit();
});
<!DOCTYPE html>
<html>
<head>
<script>
// This should log as an unhandled error with:
// IE:http://path/to/file/below(13): 'nonexistentVariable' is undefined
nonexistentVariable.shouldFail();
</script>
<script>
// This should callPhantom successfully and print
// 'CALLBACK { "hello": "world" }'
window.callPhantom({hello: "world"});
</script>
</head>
<body>
</body>
</html>
IE:http://path/to/file/below(13): 'nonexistentVariable' is undefined
CALLBACK { "hello": "world" }
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.