Forum Archive

WebView bug

blmacbeth

In both the latest betas (Pythonista2 and Pythonista3) when running web_view.eval_js('alert(document.title)'), the alert is unable to be dismissed.

Test code:

import ui
web_view = ui.WebView(frame=(0,0,500,500))
web_view.present('sheet')
web_view.load_url('https://www.google.com')
web_view.eval_js('alert(document.title)')
omz

I see, I'm not completely sure about the best way to fix this yet, but here's a possible workaround:

import ui
from objc_util import ObjCInstance, on_main_thread

web_view = ui.WebView(frame=(0,0,500,500))
web_view.present('sheet')
web_view.load_url('https://www.google.com')

js = 'alert(document.title)'
wv = ObjCInstance(web_view).subviews()[0]
on_main_thread(wv.stringByEvaluatingJavaScriptFromString_)(js)
Webmaster4o

I can confirm that this is still a bug on iOS 9.3 beta, where all the web dialogs were redone.