From 90572871717044a88274a17e5a7b76be6d0277c9 Mon Sep 17 00:00:00 2001 From: IceArmy Date: Sat, 20 Aug 2011 18:50:56 -0700 Subject: [PATCH] Add callback for page initialization. #143 --- python/pyphantomjs/bootstrap.js | 2 ++ python/pyphantomjs/webpage.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/python/pyphantomjs/bootstrap.js b/python/pyphantomjs/bootstrap.js index 229457d7..16d82852 100644 --- a/python/pyphantomjs/bootstrap.js +++ b/python/pyphantomjs/bootstrap.js @@ -19,6 +19,8 @@ window.WebPage = function() { // deep copy page.settings = JSON.parse(JSON.stringify(phantom.defaultPageSettings)); + defineSetter("onInitialized", "initialized"); + defineSetter("onLoadStarted", "loadStarted"); defineSetter("onLoadFinished", "loadFinished"); diff --git a/python/pyphantomjs/webpage.py b/python/pyphantomjs/webpage.py index 17cb254b..69017549 100644 --- a/python/pyphantomjs/webpage.py +++ b/python/pyphantomjs/webpage.py @@ -64,6 +64,7 @@ class CustomPage(QWebPage): class WebPage(QObject): + initialized = pyqtSignal() javaScriptAlertSent = pyqtSignal(str) javaScriptConsoleMessageSent = pyqtSignal(str, int, str) loadStarted = pyqtSignal() @@ -84,6 +85,7 @@ class WebPage(QObject): self.m_webPage = CustomPage(self) self.m_mainFrame = self.m_webPage.mainFrame() + self.m_mainFrame.javaScriptWindowObjectCleared.connect(self.initialized) self.m_webPage.loadStarted.connect(self.loadStarted) self.m_webPage.loadFinished.connect(self.finish)