Issue with Webviews on floating menus: external links do not redirect to the browser

Describe the bug

Hi,

I have had a long-standing bug for Webviews on Floating Menus, where nothing happens when an external link is clicked, I am not redirected to the browser, I have tried changing the default browser several times but nothing happens.

Best regards,


Affected : Custom Floating Menus & WebView


Screenshots


Device information:

  • Type of Mac: MacBook Air M2
  • macOS version: MacOS Sonoma 14.5 (23F79)
  • BetterTouchTool version: 4.530 (45290)

I'll need to provide the external URL configuration to the floating menu webviews. For now you can paste this user script:

let openFunc = async (url) => {
    //make use of BTT's Open URL action:
    let actionDefinition = {
      "BTTOpenURLBrowser" : "Default",
      "BTTPredefinedActionType" : 59,
      "BTTOpenURL" : url,
    }

    let result = await trigger_action({json: JSON.stringify(actionDefinition), wait_for_reply: false});

}


window.open = openFunc;

// overriding like this will open any a href link in the external browser. You could modify this to only apply to external links, e.g. by checking whether it starts with http before passing to openFunc
document.onclick = function (e) {
  e = e ||  window.event;
  let element = e.target || e.srcElement;

  if (element.tagName == 'A') {
    openFunc(element.href);
    return false; // prevent default action and stop event propagation
  }
};

Thank you for the solution, it works on Webview with ChatGPT or Google Gemini, but I also use a Webview with Perplexity.ai, on this one the script does not work on all external links.

4.540 alpha now let's you configure this (uploading now):

1 Like

Thank you for adding the feature. I just did the update, it works perfectly. How do we use the "Hide Floating Menu If System Browser Has Been Opened" option?

ah that should have been a checkbox. Fixed in 4.541 (uploading now)

1 Like

Thank you for the correction. I tried it just now. I checked the option, but when I click on a link in a WebView and get redirected to the browser, the floating menu doesn't hide. It stays in the foreground.

ah you are right, in some situations this didn't work. Should be fixed in 4.542 alpha! (uploading)

Thank you, it's working correctly now, perfect. I just noticed a small bug in some cases when trying to open links on WebViews with Google Gemini or Perplexity, nothing happens and the window closes.

Here is a video to show the problem :slight_smile:

is maybe the user script from earlier in the post still active?

No, I deleted the script as soon as you added the new function.