Replies: 3 comments
-
Anthropic Claude.ai suggested: This updated version uses Manifest V3 and includes some structural changes to comply with the new manifest version. Here are the key differences and explanations: manifest.json: Changed manifest_version to 3. content.js: This script now uses chrome.runtime.getURL() to get the URL of injected.js. injected.js: This is a new file containing the actual code to be injected into the JupyterLab page. The main changes in this Manifest V3 version are: Improved security: By using a separate injected.js file, we avoid potential issues with Content Security Policy (CSP) restrictions. To use this extension: Create a new directory for your extension. Remember to adjust the URL patterns in manifest.json to match your specific JupyterLab instance. // manifest.json
{
"manifest_version": 3,
"name": "JupyterLab Extension Injector",
"version": "1.0",
"description": "Injects custom JavaScript into JupyterLab pages",
"permissions": [
"scripting"
],
"host_permissions": [
"https://*.cloud.google.com/*" // Adjust this URL pattern as needed
],
"content_scripts": [
{
"matches": ["https://*.cloud.google.com/*"], // Adjust this URL pattern as needed
"js": ["content.js"],
"run_at": "document_idle"
}
],
"web_accessible_resources": [
{
"resources": ["injected.js"],
"matches": ["https://*.cloud.google.com/*"] // Adjust this URL pattern as needed
}
]
}
// content.js
(function() {
function isJupyterLabPage() {
return document.querySelector('#jupyterlab-main') !== null;
}
function injectCustomScript() {
const script = document.createElement('script');
script.src = chrome.runtime.getURL('injected.js');
(document.head || document.documentElement).appendChild(script);
}
if (isJupyterLabPage()) {
injectCustomScript();
}
})();
// injected.js
(function() {
console.log('Custom JupyterLab script injected!');
function addCustomButton() {
const toolbar = document.querySelector('.jp-Toolbar-item');
if (toolbar) {
const button = document.createElement('button');
button.textContent = 'Custom Action';
button.onclick = () => alert('Custom action performed!');
toolbar.appendChild(button);
}
}
const checkInterval = setInterval(() => {
if (document.querySelector('.jp-Toolbar-item')) {
clearInterval(checkInterval);
addCustomButton();
}
}, 1000);
})();``` |
Beta Was this translation helpful? Give feedback.
-
@MRYingLEE there isn't a way to do this at the moment in JupyterLab. However I think there is an issue in the JupyterLab repo tracking this, so extensions could more easily be added dynamically. Maybe something along the lines of https://github.com/jupyterlab/jupyterlab-plugin-playground could be a good starting point. |
Beta Was this translation helpful? Give feedback.
-
@jtpio Thanks for the sharing. This topic is worth being discussed further. In big companies no one really uses Jupyterlab extensions because real end users have no rights to install them while the IT department declines to provide customized Jupyterlab services. |
Beta Was this translation helpful? Give feedback.
-
In companies, usually there are some existing Jupyterlab services, such as GCP Vertex AI workbench. End users are out of control of the services so that we cannot install any Jupyterlab extensions, even frontend ones, while we can install Chrome extension.
In theory, all Jupyterlab frontend extensions finally become as some Javascript files. So, I am wondering there should be a general way to migrate a Jupyterlab frontend extension as a Chrome extension for Jupyterlab service.
Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions