shortkeys icon indicating copy to clipboard operation
shortkeys copied to clipboard

'Run JavaScript' does not work on some sites

Open hababr opened this issue 1 year ago • 3 comments

mail.google.com:

TypeError: Failed to set the 'textContent' property on 'Node': This document requires 'TrustedScript' assignment.
    at HTMLDocument.<anonymous> (script-to-inject.js:1:111)

linkedin.com:

Refused to execute inline script because it violates the following Content Security Policy directive:

hababr avatar May 08 '24 07:05 hababr

Same on mail.google.com

vtexperts avatar May 08 '24 14:05 vtexperts

Duplicate of #599

tjhorner avatar May 09 '24 00:05 tjhorner

Duplicate of #599

Too bad TrustedScript is not mentioned there.

piotr-dobrogost avatar May 09 '24 12:05 piotr-dobrogost

This symptom has not been resolved in the latest version of Shortkeys, 4.1.3.

Currently it also occurs on youtube.com.

TrustedScript will not work without modifying the way the script is injected.

script-to-inject.js:1 
        
       Uncaught TypeError: Failed to set the 'textContent' property on 'Node': This document requires 'TrustedScript' assignment.
    at HTMLDocument.<anonymous> (script-to-inject.js:1:111)
document.addEventListener("shortkeys_js_run", (function(e) {
    let t = document.createElement("script");
    t.textContent = e.detail,
    document.body.appendChild(t),
    document.body.removeChild(t)
}
));

oniatsu avatar Aug 08 '24 03:08 oniatsu

@oniatsu Works on the latest commit.

hababr avatar Aug 10 '24 13:08 hababr

@hababr Thank you! I haven't checked it works yet, but looking at the commit log, it seems to have been fixed in the latest commit.


However, I would install the latest version from the Chrome Web Store if possible. I don't know why the latest version of the merged commit from a month ago is not up on the Chrome Web Store.

oniatsu avatar Aug 10 '24 14:08 oniatsu

The Web Store hasn't been updated yet because the PR that fixed it (thanks to @tjhorner) mentioned

Shortcuts with missing IDs will be added on next save. This means users will need to go to the config page at least once before their JS shortcuts will work.

I was hoping to fix that so that the upgrade itself would add missing IDs instead of forcing users to do a manual action, before updating the web store. I haven't been able to find time to mess with it, so if anyone wants to PR that, feel free!

Also @hababr you mentioned this:

@tjhorner Nice fix, thank you. After building a release for Chrome I had to fix service_worker.js, a function name was missing (registerHandlers).

Any chance you could PR that fix?

crittermike avatar Aug 12 '24 14:08 crittermike

@crittermike Will do.

hababr avatar Aug 14 '24 18:08 hababr

@crittermike Created - PR

hababr avatar Aug 14 '24 21:08 hababr

Thanks @hababr! Really appreciate it. I'll ship a webstore release as soon as I'm able to do a bit more testing. In the meantime, if anyone else is available to take a swing at testing and report any issues you find, please have at it.

crittermike avatar Aug 15 '24 14:08 crittermike

Upcoming release is posted here for anyone who has capacity to test before I publish to the webstore.

crittermike avatar Aug 21 '24 16:08 crittermike

Upcoming release is posted here for anyone who has capacity to test before I publish to the webstore.

I can confirm that it fixed the issue in chrome

andrejguran avatar Oct 04 '24 16:10 andrejguran

@crittermike When do you plan to publish it?

AlexByte avatar Nov 29 '24 16:11 AlexByte

Oof, thanks for the nudge. Just submitted it for webstore review.

crittermike avatar Dec 09 '24 15:12 crittermike