0

To help Chrome (my default browser) handle the sorts of hyperlinks related to Skype For Business meeting rooms at my workplace, I wrote a tampermonkey script like this:

// ==UserScript==
// @name Forward Skype
// @namespace mailto:aschepler@example.com
// @description Pass Skype Meeting links to Skype
// @match https://meet.example.com/*
// @exclude https://meet.example.com/meet/*
// @run-at document-start
// @version 0.1
// @grant window.close
// ==/UserScript==
window.location.replace("conf:sip:" + window.location.href);
window.close();

(The "conf:sip:" prefix forms the strange URI to get Windows to recognize the protocol for which the Skype app will accept the request. Luckily, it turns out the IE-specific magic within the target page ends up essentially building this URI that includes the original HTTPS request.)

Without the window.close(), this would successfully bring up the Skype meeting requested, but then leaves a blank tab open in Chrome. So I just want to get rid of that after doing the redirect.

The trouble is that the first time someone tries to use a link with this script enabled, a popup dialog "Open URL:Conf protocol?" appears, asking whether Chrome should automatically pass along requests of this sort coming from a web page. If that has previously been permanently allowed, there's no issue. But in the script shown, the replace() returns while the dialog is still open and waiting for input, and then window.close() gets rid of the tab and the dialog, before the user has any chance to answer it.

I can easily enough make sure Chrome on my computer will allow this, and use the script myself. But I'd like to share it with coworkers, without the extra instructions of "after you've checked that opening links no longer creates that popup, go to the Tampermonkey dashboard, edit the script, and uncomment the window.close(); line."

I've looked for events and callbacks that might let the script detect any difference at all between successfully sending the conf:sip: to Windows and Skype versus opening that dialog and waiting for an answer. I did addEventListener for every property of document which starts with "on". I set up a MutationObserver for the document and its entire tree. But all I get is a readystatechange event with state complete during the replace(), in both scenarios.

Maybe I could add some sort of script config page, but that seems like a big effort for this little helper script.

Is there any way to determine from a tampermonkey script whether this sort of protocol setting is already set, or whether this type of dialog has been opened or is currently shown? Or other solutions to this problem?

I did find the existing question How to detect browser's protocol handlers?, but most of the somewhat useful answers there seem to rely on a blur event, which could be helpful in many cases when a web page wanting to open an app already has user focus, but in my case I have a brand new tab which probably isn't even initially visible.

aschepler
  • 70,891
  • 9
  • 107
  • 161
  • Chrome UI dialogs (that aren't browsing windows) cannot be detected by extensions. You can add a flag that is set to true after the script runs for the first time and store/use it via GM_setValue/GM_getValue - when there's no value on the first run you won't invoke close(). – wOxxOm Aug 31 '19 at 05:05
  • @wOxxOm Yes, but then if a user accidentally closes the tab, selects "No", or doesn't check the "Always" box, there's the same issue. – aschepler Aug 31 '19 at 13:47
  • You can add a config dialog in TM's menu via GM_registerMenuCommand https://puu.sh/EbLKh/ca70458a02.png – wOxxOm Aug 31 '19 at 13:59

0 Answers0