-
Notifications
You must be signed in to change notification settings - Fork 51
WebPage.onInitialized is not called when set #47
Comments
I think I've got something working for this using the |
…hile the document is loading using the Navigated event. Resolves sdesalas#47
There's actually another bug related to this. The toolset added to the window (json2 and ie tools) aren't actually available until the page This can be fixed very easily by moving the |
Hi @tejacques, like your fix. Will get to it ASAP. |
HI @tejacques, Added a fix for this bug. Had to call Thanks for your help and for the detailed test example. My unit tests are running ok now. Let me know how you go. |
Btw. I noticed that if I move 'onInitialized' to the 'Navigated' browser event I can write to global context on the webpage (but not read as the DOM is not available yet).. might consider moving functionality there if PhantomJS behaves the same way. |
In phantomJS Here's an example to test with: TestPage.html <!DOCTYPE html>
<html>
<head>
<title>Test Page</title>
</head>
<body>
<script>
callPhantom({ hello: 'from script tag' });
window.onload = function () {
callPhantom({ hello: 'from onload' });
}
</script>
</body>
</html> TestScript.js var webPage = require('webpage');
var page = webPage.create();
page.onInitialized = function () {
console.log("Initialized");
}
page.onCallback = function(data) {
console.log('CALLBACK: ' + JSON.stringify(data));
// Prints 'CALLBACK: { "hello": "world" }'
};
page.onConsoleMessage = function (msg) {
console.log(msg);
};
page.evaluate(function () {
callPhantom({ hello: 'world' });
});
page.open('http://localhost:port/path/to/TestPage.html', function (status) {
phantom.exit();
}); PhantomJS Output:
TrifleJS Output:
Currently, TrifleJS isn't calling onInitialized at all unless a page is loaded, and onInitialized is called after the page runs, but before onload. |
Hiya, Thanks for the great test example, I've used it to determine the load order for main lifecycle events (including onLoadStarted and onLoadFinished) and got the following from PhantomJS:
I've replicated this order (except for the first event) in my unit tests so I dont break it later. The event missing is the |
Bug
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).
Steps to Reproduce
run:
onInitialized.js:
Expected Output (PhantomJS)
Actual Output (TrifleJS)
The PhantomJS spec says (http://phantomjs.org/api/webpage/handler/on-initialized.html):
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.
The text was updated successfully, but these errors were encountered: