From 68d05d7537146d4efa6869c3afd249c2ed6787e4 Mon Sep 17 00:00:00 2001 From: Google Colaboratory Team Date: Tue, 3 Dec 2024 17:14:46 -0800 Subject: [PATCH] No public description PiperOrigin-RevId: 702520489 --- help.html | 24 ++++++++++++++++++++++++ service_worker.ts | 18 ++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 help.html diff --git a/help.html b/help.html new file mode 100644 index 0000000..b384729 --- /dev/null +++ b/help.html @@ -0,0 +1,24 @@ + + + + + Open in Colab + + + +

+ This page is not supported. +

+

+ + Open in Colab + + supports GitHub-hosted .ipynb files. +

+ + diff --git a/service_worker.ts b/service_worker.ts index 888ce33..faf9d6d 100644 --- a/service_worker.ts +++ b/service_worker.ts @@ -17,21 +17,35 @@ import {githubToColabUrl} from './parse'; +// Details for calls to chrome.action.setPopup; see +// https://developer.chrome.com/docs/extensions/reference/api/action#method-setPopup. +const EMPTY_POPUP = { + popup: '' +}; +const HELP_POPUP = { + popup: 'help.html' +}; + // This listener is called when the user clicks the extension icon. // // If the current URL matches a Jupyter notebook hosted on github.com or on // gist.github.com, this function will open a new tab and load the notebook into // Colab. -chrome.action.onClicked.addListener((tab: chrome.tabs.Tab) => { +chrome.action.onClicked.addListener(async (tab: chrome.tabs.Tab) => { if (!tab.url) { console.warn('Open in Colab was invoked without a URL.'); return; } const colabUrl = githubToColabUrl(tab.url); if (!colabUrl) { + // Set and show a helpful popup page when the extension icon is clicked on + // an invalid URL, then unset it in case the next click is valid. + await chrome.action.setPopup(HELP_POPUP); + await chrome.action.openPopup(); + await chrome.action.setPopup(EMPTY_POPUP); console.warn(`Current page (${ tab.url}) is not recognized as a GitHub-hosted notebook.`); return; } - chrome.tabs.create({'url': colabUrl}); + await chrome.tabs.create({'url': colabUrl}); });