From 14d69d12d81e87a3d6409efc79bdb9962679a99b Mon Sep 17 00:00:00 2001 From: Google Colaboratory Team Date: Mon, 9 Sep 2024 15:30:01 -0700 Subject: [PATCH] No public description PiperOrigin-RevId: 672695912 --- google/colab/output/_util.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/google/colab/output/_util.py b/google/colab/output/_util.py index 5d19251b..012a9c4d 100644 --- a/google/colab/output/_util.py +++ b/google/colab/output/_util.py @@ -15,7 +15,6 @@ import json import sys -import warnings # pytype: disable=import-error from IPython import display @@ -93,7 +92,9 @@ def serve_kernel_port_as_iframe( display.display(display.Javascript(code)) -def serve_kernel_port_as_window(port, path='/', anchor_text=None): +def serve_kernel_port_as_window( + port, path='/', anchor_text=None, skip_warning=False +): """Displays a link in the output to open a browser tab to a port on the kernel. DEPRECATED; Browser security updates have broken this feature. Use @@ -110,12 +111,14 @@ def serve_kernel_port_as_window(port, path='/', anchor_text=None): port: The kernel port to be exposed to the client. path: The path to be navigated to. anchor_text: Text content of the anchor link. + skip_warning: If True, don't print a warning about this function sometimes + not working. """ - warnings.warn( - 'This has been deprecated due to changes in browser security. Use' - ' `serve_kernel_port_as_iframe` instead.', - DeprecationWarning, - ) + if not skip_warning: + print( + '\x1b[31mWarning: This function may stop working due to changes in' + ' browser security.\nTry `serve_kernel_port_as_iframe` instead. \x1b[0m' + ) if not anchor_text: anchor_text = 'https://localhost:{port}{path}'.format(port=port, path=path)