Shadowpheonix
Shadowpheonix wrote:For some reason, I cannot seem to use
Chrome.GetPageByTitle("page title"). When I try, it always fails to retrieve the page.
Completely my fault. I forgot to
return the page found in that helper function (also
GetPageByURL). It will be fixed in the next release.
KusochekDobra
KusochekDobra, I am going to break down my replies to your posts into a numbered list for easier reference.
# 1
KusochekDobra wrote:If under the control of the script will be several pages and all of them will be send a messages, then we need implement the concept of the event stack for make a manage all of them without transmittance.
I am not sure what you mean by the word "transmittance". From context I think it means something like blocking the event listener thread?
Would you be able to produce some code that demonstrates the problem which is solved by implementing your own event queue? From my tests things act more or less the same both with and without using the queue. (replacing
this.e.InsertEvent(msg.text) with
this.e.bFunction.Call(msg.text). The code I used to test is shown below.
Code: Select all
; After creating an instance of chrome with two tabs of about:blank, and the callback "Callback"
Page1 := ChromeInst.GetPage(1)
Page2 := ChromeInst.GetPage(2)
if (!Page1 || !Page2)
throw Exception("Coudln't load pages")
Page1.Call("Console.enable")
Page2.Call("Console.enable")
Page1.Evaluate("setInterval(function(){ console.info('page1'); }, 1000);")
Page2.Evaluate("setInterval(function(){ console.info('page2'); }, 1000);")
return
Callback(Event)
{
MsgBox, % Event
}
# 2
Code: Select all
; Finds a running process chrome.exe with a parameter 'remote-debugging-port'
FindStartedDEV() {
findMe := "--remote-debugging-port=" . this.DebugPort
for Item in ComObjGet( "winmgmts:" ).ExecQuery("Select * from Win32_Process") {
if (Item.Name == "chrome.exe" && InStr(Item.Commandline, findMe))
return true
} return false
}
In what context do you use FindStartedDEV? It looks like it could be useful but I'm not sure how.
I might want to adapt this into a utility function that returns a list of ports for chrome instances running the debug protocol.
# 3
Code: Select all
if (funcName) {
this.e := New this.EventQueue(funcName)
this.BoundKeepAlive := this.Call.Bind(this, "Browser.getVersion",, False)
}
Why is BoundedKeepAlive now conditional?
# 4
Code: Select all
if (this.e && data.method == "Console.messageAdded" && (msg := data.params.message).level == "info")
this.e.InsertEvent(msg.text)
Why limit callbacks to only
console.info() messages? There are other callbacks that could be useful to a user such as
Page.frameNavigated or messages generated by
console.log.
# 5
Code: Select all
InsertEvent(msg) {
this.eventStack.InsertAt(1, msg)
ePop := this.ePop
SetTimer,% ePop, -10
}
Setting a timer for a class method function increases the reference count, meaning that the class cannot be garbage collected until that timer is deleted. Your queue function doesn't appear to have a method for removing this timer, so as the script connects to and disconnects from pages it will slowly leak memory.
My suggestion would be to modify
_PopEvent() so that, before the
while loop it calls
SetTimer,% ePop, Delete. This way the timer will be deleted and the reference count will go down whenever the timer is no longer needed.
Stavencross
Stavencross wrote:Really been digging in to this Lib, its so helpful! Just want to see if ya'll have a better way on how to scrape the JSON I've been grabbing from these pages. Here is my code:
*snip*
If you check jsonGrabber(), you'll see I'm grabbing the JSON from the page DOM. I grab the innerHTML of the page, and run strReplace to get rid of the <pre> tags. I thought I'd see if ya'll had a better way to accomplish this as it feels dirty. I'm also open to any other code optimizations you could throw my way. I've been working on my coding skills a lot in the last 6 months and I know I really need to start pushing myself to write better & more modular code
It's hard to say without access to the actual page, but I would bet that grabbing from
document.body.innerText would work better for you than
document.body.innerHTML
maitresin
maitresin wrote:Hi,
I got 2 questions:
1-How I could save my profil and cookies? I mean if I log into a website I want to be able to launch this chrome and still be logged in my account.
2-How I could download an .html page like the exemple .pdf but .html. It also need to be save cookies and keep connection active for downloading the .html from my account (which is only downloadable from account).
Thanks!
- If you use the same profile folder each time the cookies will persist. You could start a chrome instance using that profile, log in manually, then use the script to do things after you've logged in. Alternatively, you could automate the login process so it logs in automatically. Also, if there isn't already a non-debug chrome instance running under the default profile, you could use this library to start a debug instance with the default profile and it should just work.
- If you just need the source of a particular page, such as is shown when you press control-u on a webpage, you should be able to access it with PageInst.Evaluate("document.children[0].outerHTML").value. If you need the entire page plus its resources, such as is downloaded when you press control-s on a webpage, I'm not sure if that's possible from this interface.