Assume I do the following:
const
externalVal = 'something',
fn = () => {
console.log(externalVal)
})
console.log(fn.toString())
The console log will stringify the function and specifically, console.log(externalVal)
will be stringified.
Is there any way I can get the function block to convert to a string but contain the value of externalVal
so it would come out like: console.log('something')
?
The reason being is I can't access the pages window object via a browser extension content script, but I can inject a script into the document and run it - this doesn't help much unless I can pass in the value as well.
Just to clarify, I know I can access the the window object by injecting the script. That's the purpose of this question because I need to pass a value into that script and converting the function to a string isn't eval'ing the value of the variable.