apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.63k stars 840 forks source link

NetBeans Connector in the Chrome Web Store is outdated #6601

Open vieiro opened 10 months ago

vieiro commented 10 months ago

Apache NetBeans version

Apache NetBeans latest daily build

What happened

The NetBeans Connector in the Chrome Web Store needs to be updated to work on recent versions of Chrome, if this is possible, or be removed from the Chrome Web Store.

Sources for the connector seem to be still available at extbrowser/plugins.

The message in the IDE log looks like this:

INFO [org.netbeans.ui.metrics.web.clientproject]: USG_PROJECT_HTML5_CONFIGURE
INFO [org.netbeans.modules.extbrowser.plugins.chrome.ChromeManagerAccessor.ChromeExtensionManager]: Could not find chrome extension in installation directory!
INFO [org.netbeans.modules.web.webkit.debugging.api.Debugger]: Enable failed: {"id":0,"error":"{\"message\":\"Cannot attach to this target.\"}"}
INFO [org.netbeans.modules.extbrowser.plugins.chrome.ChromeManagerAccessor.ChromeExtensionManager]: Could not find chrome extension in installation directory!
INFO [org.netbeans.modules.web.webkit.debugging.api.Debugger]: Enable failed: {"id":1,"error":"{\"message\":\"Cannot attach to this target.\"}"}

How to reproduce

  1. Install the "NetBeans Connector" from the Chrome Web Store.
  2. Create an HTML5 project (I've used a HTML5 template)
  3. Try to run the "index.html" file.

Did this work correctly in an earlier version?

NetBeans 8.2

Operating System

Any operating system (I'm on Linux). This used to work in NB8.2.

JDK

JDK11, not important.

Apache NetBeans packaging

Own source build

Anything else

Issue https://github.com/apache/netbeans/issues/4987 is probably the same problem. Closing it in favor of this one.

Are you willing to submit a pull request?

No

vieiro commented 10 months ago

It seems the plugin has a manifest version 2, but Chrome cannot run manifest version2 plugins since January, 2023.

So the plugin should be upgraded to manifest version 3. This will require replacing the background page with a service worker and changing security policy permissions, etc. This is a nice description on the changes required for the upgrade.

Anyone with experience in Chrome plugins wants to tackle the problem?

mhalachev commented 5 months ago

Indeed, it would be advisable to upgrade the extension to Manifest V3, preferably along with the next NB release, as Manifest V2 extensions are likely to be phased-out in the not-so-distant future.

https://developer.chrome.com/blog/resuming-the-transition-to-mv3

TL;DR

We will begin disabling Manifest V2 extensions in pre-stable versions of Chrome (Dev, Canary, and Beta) as early as June 2024 […] Users [...] will see Manifest V2 extensions automatically disabled in their browser and will no longer be able to install Manifest V2 extensions from the Chrome Web Store. […] We expect it will take at least a month […] before expanding the rollout to stable channel Chrome.

The process will require rewiring some internals while replacing the background page with a service worker.

@mbien Would it be appropriate to get in touch with Jan Stola regarding the extension refactoring?

@viero To date, the extension still functions, with some workarounds. First, the extension shall be manually enabled. Then, When Run Project is selected, NetBeans presents a message “Browser refused to debug this tab…”. However, if “Debug in NetBeans” is clicked from the extension’s menu right away, it performs as expected.

mbien commented 5 months ago

Would it be appropriate to get in touch with Jan Stola regarding the extension refactoring?

@mhalachev If you want to ask to please refactor the plugin then probably not since too much time passed already ;)

@neilcsmith-net @ebarboni do we have access to the account which manages the plugin at the chrome store? If not: we should at some point try to take the plugin down since its not ideal when it points back to NB and we can't upload a new release.

mhalachev commented 5 months ago

@mbien Better late than never ;) The extension is very useful for web frontends and it would be nice to keep.

I attempted some tinkering with this and was able to get a working Manifest V3 extension to some extent (debugging starts without an error, Browser DOM appears in NetBeans, changes propagate in Chrome, etc.) but the extension UI within the browser is now broken.

Here is what what the Manifest V3 looks like:

{
    "name": "__MSG__pluginName__",
    "description": "__MSG__pluginDescription__",
    "manifest_version": 3,
    "minimum_chrome_version": "88",
    "version": "1.1.6",
    "homepage_url": "https://chrome.google.com/webstore/detail/netbeans-connector/hafdlehgocfcodbgjnpecfajgkeejnaa",
    "background": {
        "service_worker": "js/background.js"
    },
    "devtools_page": "html/devtools.html",
    "options_page": "html/options.html",
    "action": {
        "default_icon": "img/netbeans16.png",
        "default_title": "Open NetBeans actions",
        "default_popup": "html/popup.html"
    },
    "permissions": [
        "contextMenus",
        "tabs",
        "debugger",
        "storage"
    ],
    "content_security_policy": {
        "extension_pages": "default-src 'self'; connect-src ws://127.0.0.1:8008/"
    },
    "icons": {
        "16": "img/netbeans16.png",
        "48": "img/netbeans48.png",
        "128": "img/netbeans128.png"
    },
    "default_locale": "en"
}

The service worker itself:

importScripts('../i18n/i18n.js', './common.js', './chrome.js');

chrome.runtime.onStartup.addListener(function() {
    chrome.action.disable();  
});

Currently this is only a "duct tape fix", just to get things up and running at all. Ideally, all extension lifecycle stuff from common.js and chrome.js should go here. Ref. Migrate to a service worker.

Also replaced some unsupported APIs and was able at least get the context menu item partially working:

chrome.js, l.91 chrome.pageAction.show(tabId); > chrome.action.enable(tabId);

...the context menu itself at line 119:

    chrome.contextMenus.removeAll(function() {
        chrome.contextMenus.create({
            id: 'selectionMode',
            title: NetBeans.contextMenuName(),
            contexts: ['all'],
            documentUrlPatterns: [NetBeans.contextMenuUrl],
//  onclick does not work anymore with Manifest V3           
//            onclick: function() {
//                NetBeans.setSelectionMode(!NetBeans.getSelectionMode());
//            }
        },
        function() {
            NetBeans.contextMenuCreationInProgress = false;
        });
// Instead, addListener should be used...
        chrome.contextMenus.onClicked.addListener((info, tab) => {
            if (info.menuItemId === 'selectionMode') {
                NetBeans.setSelectionMode(!NetBeans.getSelectionMode());
            }
        })

common.js l.182 chrome.extension.onMessage.addListener > chrome.runtime.onMessage.addListener

This is the progress thus far. While it's not extensive, it might serve as a starting point. :) Although very well crafted, the extension is not overly simplistic, and while seeing it for the first time still need to figure out how exactly things work.

Hint: The extension can be easily loaded unpacked directly from the NB codebase for tinkering.

mhalachev commented 1 week ago

A quick update: Chrome now displays an alert for extensions using Manifest V2, indicating that support for these extensions may soon be discontinued.

chrome-extensions-alert

PS: Find alternative points here: https://chromewebstore.google.com/detail/hafdlehgocfcodbgjnpecfajgkeejnaa/related-recommendations