Question: how to get navigation event
Closed this issue · 5 comments
I have to solve a captcha, that is not under my control. When it's solved I need to get the url where it redirects to. How can i do this?
I tried this, but its not working at all
[...]lot of code before
defer a.Close()
// Start astilectron
if err := a.Start(); err != nil {
log.Debugln(errors.Wrap(err, " main: starting astilectron failed"))
}
a.On(astilectron.EventNameAppCrash, func(e astilectron.Event) (deleteListener bool) {
log.Errorln(" Electron App has crashed", e)
return
})
a.On(astilectron.EventNameWindowEventWillNavigate, func(e astilectron.Event) (deleteListener bool) {
log.Errorln(" Electron navigation", e)
return
})
a.On(astilectron.EventNameWindowEventWebContentsExecutedJavaScript, func(e astilectron.Event) (deleteListener bool) {
log.Errorln(" Electron navigation js", e)
return
})
a.On(astilectron.EventNameWindowEventDidGetRedirectRequest, func(e astilectron.Event) (deleteListener bool) {
log.Errorln(" Electron navigation rr", e)
return
})
a.HandleSignals()
// New window
var w *astilectron.Window
var err error
center := true
height := 800
width := 600
if w, err = a.NewWindow("https://signalcaptchas.org/registration/generate.html", &astilectron.WindowOptions{
// if w, err = a.NewWindow("http://"+config.ServerHost+":"+config.ServerPort, &astilectron.WindowOptions{
Center: ¢er,
Height: &height,
Width: &width,
}); err != nil {
log.Debugln("", errors.Wrap(err, "main: new window failed"))
}
// Create windows
if err = w.Create(); err != nil {
log.Debugln("", errors.Wrap(err, "main: creating window failed"))
}
log.Debugln(" open dev tools", config.ElectronDebug)
if config.ElectronDebug {
w.OpenDevTools()
}
w.Session.ClearCache()
// Blocking pattern
a.Wait()
It seems the redirection is blocked by the browser. When I successfully verify a Catcha on your URL, it tries to redirect to a URL of the type signalcaptcha://...
and I get the error Failed to launch '...' because the scheme does not have a registered handler
on Chrome (therefore Chromium is most likely behaving the same). If it redirected to HTTP, it would be caught with EventNameWindowEventDidGetRedirectRequest
Is it possible that i inject a global function? Or register a custom url scheme? Nevertheless thanks for your really quick response!
I found it in the code :) w.ExecuteJavaScript
Does it fix your problem ?
Yes, i trigger another redirect instead of trying to open an ivalid url scheme.