Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: launch_url fails with pop-up blocker on safari #1105

Closed
gbrandt opened this issue Feb 27, 2023 · 9 comments
Closed

bug: launch_url fails with pop-up blocker on safari #1105

gbrandt opened this issue Feb 27, 2023 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@gbrandt
Copy link

gbrandt commented Feb 27, 2023

using launch_url with web_window_name of "_blank" fails on safari due to too much delay (as per flutter/flutter#78524)

I have done all I can to reduce the delay, but the time it takes for a button click to go from the browser to the server and back is enough to stop Safari from opening the new tab.

Code example to reproduce the issue:

import flet as ft


def main(page: ft.Page):
    page.add( ft.ElevatedButton("Hello World", on_click=lambda e: e.page.launch_url( "https://google.com")))


ft.app(target=main, view = ft.WEB_BROWSER)

I expected a new tab to open but instead get a message about a blocked pop up

Screenshot 2023-02-27 at 15 14 59

Does not occur on firefox

Name: flet
Version: 0.4.2
Summary: Flet for Python - easily build interactive multi-platform apps in Python
Home-page:
Author: Appveyor Systems Inc.
Author-email: [email protected]
License: Apache-2.0
Location: /Users/gregor.brandt/Documents/Startbridge/web-app2/fe_env/lib/python3.11/site-packages
Requires: flet-core, httpx, oauthlib, packaging, watchdog, websocket-client, websockets
Required-by:

@gbrandt
Copy link
Author

gbrandt commented Feb 27, 2023

A webbiew would solve this issue as the link could be put into a webview and be acted on within the browser.

@ndonkoHenri
Copy link
Contributor

Just from testing flutils link to docs on iPhone Safari and had thesame issue. (No new tab with the expected link)

@gbrandt
Copy link
Author

gbrandt commented Mar 7, 2023

The only way to fix this is to get the link click action in safari itself and not incur a roundtrip to the server.

@gbrandt gbrandt changed the title launch_url fails with pop-up blocker on safari bug: launch_url fails with pop-up blocker on safari Apr 14, 2023
@FeodorFitsner FeodorFitsner added the bug Something isn't working label Apr 19, 2023
@FeodorFitsner
Copy link
Contributor

I've been thinking a lot about this issue. It's no-go of cause...

How about we add a new href (and target?) property to all buttons (and other clickable things?), so it triggers launch_url on a client side? I have a feeling it could work as delay will be negligible.

@gbrandt
Copy link
Author

gbrandt commented Apr 19, 2023

I think that may work, not sure of the timing requirement here. Any lag in the communications would cause this to fail. A work around is to have an HTML Control and let us put a <a ...> tag into it. This would kill two birds with one stone, as we could then also have a generic web view (for instance, we use chatwoot for support and we cannot use it in flet right now because we can't put html/javascript directly into an app).

One thing to think about here is links in Markdown as well, the round trip on safari means we can't open a new tab

@gbrandt
Copy link
Author

gbrandt commented Apr 19, 2023

If there was a way to have the link work 100% locally on the browser, it would work every time.

@FeodorFitsner
Copy link
Contributor

Markdown is not a problem as we could add something like autofollow_links and open them directly on the client.
I'll give it a try.

@FeodorFitsner FeodorFitsner self-assigned this Apr 19, 2023
@FeodorFitsner
Copy link
Contributor

FeodorFitsner commented Apr 24, 2023

I've made a small prototype with url parameter for ElevatedButton:

import flet as ft


def main(page: ft.Page):
    page.add(
        ft.ElevatedButton(
            "Open with CLICK",
            on_click=lambda e: e.page.launch_url("https://google.com"),
        ),
        ft.ElevatedButton("Open with URL", url="https://google.com"),
    )

ft.app(target=main, view=ft.WEB_BROWSER)

Clicking "Open with URL" button on Safari successfully opens a new tab with 100% reliability while, as expected, clicking "Open with CLICK" gives a blocked popup.

I'm going ahead and add url and url_target to all "clickable" controls:

  • Container
  • ElevatedButton
  • FilledButton
  • FilledTonalButton
  • FloatingActionButton
  • IconButton
  • ListTile
  • OutlinedButton
  • TextButton
  • TextSpan

New properties added to Markdown to auto-follow links:

  • auto_follow_links - default is False. on_tap_link event fires anyway.
  • auto_follow_links_target - default is _blank - new tab/window.

@FeodorFitsner
Copy link
Contributor

The solution could be tried with Flet pre-release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants