toga icon indicating copy to clipboard operation
toga copied to clipboard

Make WebView.set_content()'s URL argument optional

Open hyuri opened this issue 1 year ago • 1 comments

What is the problem or limitation you are having?

Currently, the url argument in set_content() is required. But it stands to reason that, if you are directly setting raw HTML content, that content doesn't have a URL associated with it.

What we can currently do is pass an empty string to url: my_webview.set_content("", content=html_content)

But that's clunky.

Describe the solution you'd like

In the set_content() function, make the url argument optional.

Describe alternatives you've considered

Perhaps #2851 can make this issue obsolete.

Additional context

No response

hyuri avatar Sep 17 '24 03:09 hyuri

Your assertion is incorrect - even if you don't specify a URL, a webview has a URL. That URL might be about:blank - but it's still a URL, and it can impact how page content is interpreted. GTK, iOS and macOS don't have an option to not specify a URL when loading content.

The closest we could do here would be to set it up such that mywebview.content = "<html>..." is an implicit call to mywebview.set_content("", "<html>...") - but the additional complication is that most web APIs don't provide a way to retrieve the page HTML content - so we need to define a setter, but without a getter.

Syntactically, that's not something Python allows - but I guess we could define the getter, but make it raise AttributeError so that it looks like it doesn't exist, and document that it's a write-only property, and advise that the setter is equivalent to set_content("", content).

freakboy3742 avatar Sep 17 '24 23:09 freakboy3742

I can fix this.

johnzhou721 avatar May 01 '25 22:05 johnzhou721