Get Safari page source code in share extension.
@omz I didn't know that
@omz is there a way to have
ui.WebViewload a URL without presenting the webView?
JonB last edited by JonB
Webview also lets you use a few delegate methods which can be useful.
(edit: pointed to correct message)
the webview never needs to be presented to load.
lukaskollmer last edited by lukaskollmer
@JonB I can't get it to load the page until I called
webView = ui.WebView() webView.delegate = WebViewDelegate() webView.load_url(url) webView.present()
If I remove
present(), the delegate won't get called
This works for me:
Possibly the delegate only gets called after it is presented? I seem to recall something like that. If so, you should be able to present it once, then close it, or present in a panel.
JonB last edited by JonB
See for example:
This shows the delegate getting called without being presented.
When I tried to grab outerHTML directly at the end of the script, it has no data, because the page had not yet loaded. In the delegate webview_did_finish_load, it works fine.
Also, you could have a for loop that checks for document.readyState, to allow a more script-y sequence of commands. though you have to be a little careful because the readyState may go through complete two times initially.
ui.WebViewshare cookies between the main app and the extension?
does not look like it.
you can get cookies this way ( it would be possible to save this to a file which could be in a shared spot)
from objc_util import * storage=ObjCClass('NSHTTPCookieStorage').sharedHTTPCookieStorage() print(storage.cookies())
I have seen some stackoverflow code using NSKeyedArchiver to turn this into NSData
though i have not yet had luck in using NSKeyedUnarchiver to go from data back to an cookie storage object (just have not tried hard yet)
You can also get the binary cookie file from
jumpbeen last edited by
From Apple Developer website .
Accessing a Webpage
To add webpage access and manipulation to your app extension, perform the following steps:
In the NSExtensionActivationRule dictionary in your app extension’s Info.plist file, give the NSExtensionActivationSupportsWebPageWithMaxCount key a nonzero value. (To learn more about the activation rule dictionary, see Declaring Supported Data Types for a Share or Action Extension.)
jaimeesc last edited by
I was able to get the source code of the current Safari web page using the following code:
req = appex.get_web_page_info()
From there I was able to parse through the HTML using BeautifulSoup.