mhalachev commented on issue #6601:
URL: https://github.com/apache/netbeans/issues/6601#issuecomment-2027364265

   @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](https://developer.chrome.com/docs/extensions/develop/migrate/what-is-mv3) 
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:
   ```json
   {
       "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:
   ```javascript
   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](https://developer.chrome.com/docs/extensions/develop/concepts/service-workers/lifecycle)
 stuff from common.js and chrome.js should go here. Ref. [Migrate to a service 
worker](https://developer.chrome.com/docs/extensions/develop/migrate/to-service-workers).
   
   Also [replaced some unsupported 
APIs](https://developer.chrome.com/docs/extensions/develop/migrate/api-calls) 
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:
   
   ```javascript
       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](https://developer.chrome.com/docs/extensions/get-started/tutorial/hello-world#load-unpacked)
 directly from the NB codebase for tinkering.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to