javascript-obfuscator icon indicating copy to clipboard operation
javascript-obfuscator copied to clipboard

Chrome Extension Manifest v3 Service Worker

Open AleCucina opened this issue 2 years ago • 2 comments

I noticed there is a problem obfuscating the service worker of a manifestv3 chrome extension. Now the function to run a script is:

    const example = "Hello World!"
    chrome.scripting.executeScript({
        func: (param) => {
            console.log(param) // Hello World!
        },
        args: [example],
        target: { tabId: tabId }
    })

But probably with the obfuscated code a problem arises because what is inside the func() loses meaning since the rest of the obfuscated code is in the service worker and not in the content of the page.

Does anyone know how to fix this problem? Thanks in advance!

AleCucina avatar Jan 11 '24 11:01 AleCucina

I have the same use case, I had to create a file 'functionX' , pass 'function1' to the 'func' attribute, make the obfuscator skip function1, obfuscate the file 'functionX', and insert a function with name 'function1' and the resulte of 'functionX' obfuscation as body to the obfuscated background.js

younes-zeboudj avatar Mar 21 '24 03:03 younes-zeboudj

workaround:

// javascript-obfuscator:disable
function myfunc=(param) => {
    console.log(param) // Hello World!
}
// javascript-obfuscator:enable

   const example = "Hello World!"
    chrome.scripting.executeScript({
        func: myfunc,
        args: [example],
        target: { tabId: tabId }
    })

younes-zeboudj avatar Apr 15 '24 09:04 younes-zeboudj