toga icon indicating copy to clipboard operation
toga copied to clipboard

Javascript disabled over HTTP in WebView on macOS

Open seibert opened this issue 6 months ago • 1 comments

What is the problem or limitation you are having?

After using the Positron design pattern (WebView widget paired with HTTP server running on another thread to serve assets to the web view), I was puzzled that none of the Javascript worked, but only when I built the macOS app and ran it. Everything was fine when running the application in dev mode.

After some hunting, I discovered this Stack Overflow answer: https://stackoverflow.com/a/62537163 It explains that I need to add to the project's Info in Xcode a dictionary called "App Transport Security Settings" with a key called "Allow Arbitrary Loads" set to YES. Once I manually added this to the Xcode project, everything worked fine.

Describe the solution you'd like

It would be useful to call out this issue on the WebView documentation page. Additionally, I couldn't tell if there was a persistent way to add this Info setting in the pyproject.toml for my Briefcase app. Since I had to open Xcode to manually add this setting, I assume the setting will be lost if Briefcase ever needs to regenerate the Xcode project.

Describe alternatives you've considered

The alternative I found was to add the setting manually with Xcode after generating the project with Briefcase and hope it isn't overwritten in the future.

Additional context

No response

seibert avatar Jul 05 '25 15:07 seibert

This should be possible to accomodate by default in the template. Briefcase can inject Info.plist values; so we can add a setting defining the appropriate key to the macOS section of the Positron plugins. None of the plugins currently have a definition for this; but the Toga template that the Positron templates are based on defines a pyproject_table_macOS entry point. If we add a info."something" =True definition to the Positron template (whatever the key is called), we can ensure this setting exists for all apps.

Two notes on the implementation:

  1. We need to find the underlying key name - "Allow arbitrary loads" is the human version of the key; we need the Info.plist key. You can find this key name by manually adding the setting in the Xcode project, then inspecting the Info.plist file that is generated
  2. It might be worth introducing an abstract "Positron base" template. This macOS setting will be needed on all the Positron templates, so it makes sense to define it once and use it everywhere.

freakboy3742 avatar Jul 08 '25 01:07 freakboy3742

Could you please assign this issue to me I will be happy to work

MhussainD4772 avatar Nov 26 '25 21:11 MhussainD4772

@MhussainD4772 We don't explicitly assign issues - expressing interest in an issue (as you have done here) is all you need to do. Our contribution guide is here; if you need any additional assistance, let us know. I look forward to seeing your PR!

freakboy3742 avatar Nov 26 '25 21:11 freakboy3742

Thank you so much!!

MhussainD4772 avatar Nov 26 '25 21:11 MhussainD4772