After some try and error and error and error (damned error reporting!) this version works!

#!/usr/bin/perl use strict; use warnings; my $folder = $ARGV[0]; my $url = $ARGV[1]; (my $descr = $folder) =~ s/_+/ /g; my $longname = 'Perl genarated extension - '.$descr; mkdir $folder or die "Cannot create $folder: $!"; chdir $folder or die "Cannot enter $folder: $!"; # the manifest open MANIF, '>', 'manifest.json' or die "Cannot open a file to write i +n: $!"; my $manifest = '{ "manifest_version": 3, "description": "'.$descr.'", "background": { "service_worker": "background.js"}, "name": "'.$longname.'", "permissions": [ "contextMenus", "tabs" ], "version": "1.0" }'; print MANIF $manifest; close MANIF; # the jscript open JSCRIPT, '>', 'background.js' or die "Cannot open a file to write + in: $!"; my $background = 'chrome.runtime.onInstalled.addListener(function() { chrome.contextMenus.create({ title: "'.$descr.'", contexts: ["selection"], id: "'.$descr.'" }); }); chrome.contextMenus.onClicked.addListener(function (info, tab) { if (info.menuItemId === "'.$descr.'") { let getToSite = "'.$url.'" + info.selectionText chrome.tabs.create({index: tab.index + 1, url: getToSite, sele +cted: true}); } })'; print JSCRIPT $background; close JSCRIPT;

here the diff output from the original 9 years old code:

16c16 < "manifest_version": 2, --- > "manifest_version": 3, 19c19 < "scripts": ["background.js"]}, --- > "service_worker": "background.js"}, 28,33c28,42 < my $background ='function customfunc(info) < { < var searchstring = info.selectionText; < chrome.tabs.create({url: "'.$url.'" + searchstring}) < } < chrome.contextMenus.create({title: "'.$descr.'", contexts:["selectio +n"], onclick: customfunc});'; --- > my $background = 'chrome.runtime.onInstalled.addListener(function() +{ > chrome.contextMenus.create({ > title: "'.$descr.'", > contexts: ["selection"], > id: "'.$descr.'" > }); > }); > > chrome.contextMenus.onClicked.addListener(function (info, tab) { > if (info.menuItemId === "'.$descr.'") { > let getToSite = "'.$url.'" + info.selectionText > chrome.tabs.create({index: tab.index + 1, url: getToSite, se +lected: true}); > } > })'; >

see you in 2032 :)

L*

UPDATE If you want to add the website icon to the context menu you can download it (generally available under the root of the site like in: hhtps://example.com/favicon.ico ), transform it to a .png file (not rename; transform) and add it to the manifest.json file, after the version like in:

{ "manifest_version": 3, "description": "Description", "background": { "service_worker": "background.js"}, "name": "Perl genarated extension - Description", "permissions": [ "contextMenus", "tabs" ], "version": "1.0", "icons": { "128": "favicon.png", "16": "favicon.png", "32": "favicon.png", "48": "favicon.png", "64": "favicon.png" } }

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: [OT] migrating from scripts to service_worker in js perl generated extensions for chrome -- solved by Discipulus
in thread [OT] migrating from scripts to service_worker in js perl generated extensions for chrome by Discipulus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.