Andereoo/TkinterWeb

[Question] Regulating resources

Closed this issue · 3 comments

Good day, to one and all!

I am involved with a Python project called Blasta - An XMPP PubSub based annotation system.

blasta720p.mp4

Screenshots https://git.xmpp-it.net/sch/Blasta/src/branch/main/screenshot

The system is an annotation (also referred to as bibliography and bookmarks) management system.

I do not desire to open resources from within TkinterWeb.

Which means that using the module webbrowser is more viable over pywebview, unless it is possible to regulate access.

import webbrowser
webbrowser.open('http://localhost:8000')
python blasta.py
python -m webbrowser -t 'http://localhost:8000'

Is it possible to block or treat differently to resources outside of specified hostnames?

This matter was raise at r0x0r/pywebview#1459

Hi! I assume you looking to intercept all requests (images, stylesheets, etc) and not block the loading of all external resources all together?

Yes, that is quite easy to do. From the API Reference, can use on_link_click to override the default behaviour for hyperlinks and on_form_submit to handle form submissions. For instance, the following would open the resource in the default webbrowser rather than displaying it in TkinterWeb:

def load_new_page(url):
    webbrowser.open(url)
    
myhtmlframe.on_link_click(load_new_page)