Skip to content

Conversation

@brunoais
Copy link

@brunoais brunoais commented Jul 13, 2025

The basic workflow is:

  1. Open editor with companion extension.
  2. Get the code from editor.
  3. Open extension popup and paste the code.
  4. Use connection to edit files.

UX and UI needs work but the basic functionality and communication protocol should be good enough like this.

I'm creating this PR because I think it's ready for some initial review.

I'm expecting to create the repository and upload the example vscode extension in a few hours.

@derjanb Please do an initial review

The vscode extension can be found here: https://gitlab.com/brunoais/tampermonkey-vscode

resolves #10

brunoais added 2 commits July 13, 2025 22:07
In my case, I just have terrible issues trying to install node 18.
The basic workflow is:
1. Open editor with companion extension.
2. Get the code from editor.
3. Open extension popup and paste the code.
4. Use connection to edit files.

UX and UI needs work but the basic functionality and communication protocol should be good enough like this.
action.onClicked.addListener(async (_details) => {
void(runtime.lastError);
const openOnlineEditor = async () => {
hhp = hhp || await hasHostPermission(MAIN_URL);
Copy link
Member

@derjanb derjanb Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary if you lock in this handler like it done here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The handleMessage lock was a nightmare for me. I had to disable it to be able to figure out how to call Tampermonkey API. Even with the types you guided me, I lost so many messages which were just ignored/dumped.
The worst part of a lock is when there's no guarantee that the lock will unlock when the execution leaves the block. I wanted to try fixing that but it's too hard without knowing exactly how to make sure the lock unlocks and we don't get a non-responding extension when the user clicks too much.
I have the code like that because that's how you had your code before. I just moved some details around to stay like that.
So you think a lock should be used for that one too?

@derjanb
Copy link
Member

derjanb commented Aug 5, 2025

Sorry for the late review. I was very busy lately.
Beside some minor improvements (more and better types instead of any, ...) this looks promising. 👍

@brunoais
Copy link
Author

brunoais commented Aug 5, 2025

It's ok. You still did when you were able to.
I don't know typescript typing but I'll try to wing it.

@brunoais brunoais marked this pull request as ready for review September 1, 2025 17:55
@brunoais
Copy link
Author

brunoais commented Sep 1, 2025

@derjanb Sorry about the delay. I finally got some time and did the work of applying types to variables. Is how I did good enough?

@jubr
Copy link

jubr commented Dec 5, 2025

I'm also interested in this, is there something I can do to help?

@derjanb
Copy link
Member

derjanb commented Dec 5, 2025

@jubr Sure. Try it out, review the changes and give feedback.

I was busy recently, but will do the same, so that we can continue with this.

@derjanb
Copy link
Member

derjanb commented Dec 5, 2025

@brunoais Always feel free to ping me, in case my response takes too long... 🙈

@jubr
Copy link

jubr commented Dec 5, 2025

I'm trying to fire this up, but it looks like the "Open extension popup and paste the code." does not show up for me in the newly started VSCode instance. I do see the new tab "Tampermonkeyfs" under explorer there.

Perhaps my experience with VSCode plugins is lacking... but also the documentation is kind of sparse...

I already:

  1. built Tampermonkey - 5.4.1 vanilla
  2. built Tampermonkey Editors - brunoais:remote_editor_support
  3. built https://gitlab.com/brunoais/tampermonkey-vscode

When I could not get it to work I checked this works (and it does):

  • vanilla Tampermonkey
  • vanilla Tampermonkey Editors

I'm suspecting it might have something to do with the sed background.jsfrom the docs:

sed -i 's/"hohmicmmlneppdcbkhepamlgfdokipcd"/"kjmbknaomholdmpocgplbkgmjdnidinh"/' background.js

That does not change anything in background.js.

I've tried with both vanilla VSCode and Cursor - the latter being the real reason I'm looking into this 😜

any ideas?

@derjanb
Copy link
Member

derjanb commented Dec 5, 2025

background.js from https://www.tampermonkey.net/crx/tampermonkey_stable.crx includes hohmicmmlneppdcbkhepamlgfdokipcd at background.js line 1034. This needs to be changed to your Tampermonkey Editors package id (which should be kjmbknaomholdmpocgplbkgmjdnidinh.

@jubr
Copy link

jubr commented Dec 5, 2025

yes, so I should add my custom one after "lieodnapokbjkkdkhdljlllmgkmdokcm"

@derjanb
Copy link
Member

derjanb commented Dec 5, 2025

I should add my custom one

Yes, replace or add. this doesn't matter.

This code prevents Tampermonkey from talking to "unverified" Tampermonkey Editor extensions.

@jubr
Copy link

jubr commented Dec 5, 2025

yeah makes sense.. can it be that id is no longer in the latest release?

$ grep hohmicmmlneppdcbkhepamlgfdokipcd ./tampermonkey-unpacked/background.js

[suspiciously empty line here]

@derjanb
Copy link
Member

derjanb commented Dec 5, 2025

can it be that id is no longer in the latest release?

No, it's there. Did you run sed already? Then it already replaced by kjmbkn...

@jubr
Copy link

jubr commented Dec 5, 2025

Cool, that takes care of Tampermonkey <-> Tampermonkey Editors.

Now to get it hooked up to tampermonkey-vscode...

@jubr
Copy link

jubr commented Dec 5, 2025

amm.. memory bubbles up: compilation of that one fails, some TS errors.

It breaks on node -r esm Makefile.js pack:

image
ERROR in /Users/1000060011/jb/github.com/brunoais/tampermonkey-editors/release/chrome/release/src/background/index.ts
117:16-20
[tsl] ERROR in /Users/1000060011/jb/github.com/brunoais/tampermonkey-editors/release/chrome/release/src/background/index.ts(117,17)
      TS6133: 'fail' is declared but its value is never read.

ERROR in /Users/1000060011/jb/github.com/brunoais/tampermonkey-editors/release/chrome/release/src/background/index.ts
168:34-137
[tsl] ERROR in /Users/1000060011/jb/github.com/brunoais/tampermonkey-editors/release/chrome/release/src/background/index.ts(168,35)
      TS2345: Argument of type '(request: ExtensionRequestMessage, sender: {    id: string;}, sendResponse: ExtensionResponseMessage) => boolean' is not assignable to parameter of type '(message: any, sender: MessageSender, sendResponse: (response?: any) => void) => void'.
  Types of parameters 'sender' and 'sender' are incompatible.
    Type 'MessageSender' is not assignable to type '{ id: string; }'.
      Types of property 'id' are incompatible.
        Type 'string | undefined' is not assignable to type 'string'.
          Type 'undefined' is not assignable to type 'string'.

ERROR in /Users/1000060011/jb/github.com/brunoais/tampermonkey-editors/release/chrome/release/src/background/index.ts
176:24-36
[tsl] ERROR in /Users/1000060011/jb/github.com/brunoais/tampermonkey-editors/release/chrome/release/src/background/index.ts(176,25)
      TS2349: This expression is not callable.
  No constituent of type 'ExtensionResponseMessage' is callable.

ERROR in /Users/1000060011/jb/github.com/brunoais/tampermonkey-editors/release/chrome/release/src/background/index.ts
185:28-40
[tsl] ERROR in /Users/1000060011/jb/github.com/brunoais/tampermonkey-editors/release/chrome/release/src/background/index.ts(185,29)
      TS2349: This expression is not callable.
  No constituent of type 'ExtensionResponseMessage' is callable.

ERROR in /Users/1000060011/jb/github.com/brunoais/tampermonkey-editors/release/chrome/release/src/background/index.ts
188:28-40
[tsl] ERROR in /Users/1000060011/jb/github.com/brunoais/tampermonkey-editors/release/chrome/release/src/background/index.ts(188,29)
      TS2349: This expression is not callable.
  No constituent of type 'ExtensionResponseMessage' is callable.

ERROR in /Users/1000060011/jb/github.com/brunoais/tampermonkey-editors/release/chrome/release/src/background/index.ts
198:20-32
[tsl] ERROR in /Users/1000060011/jb/github.com/brunoais/tampermonkey-editors/release/chrome/release/src/background/index.ts(198,21)
      TS2349: This expression is not callable.
  No constituent of type 'ExtensionResponseMessage' is callable.

ERROR in /Users/1000060011/jb/github.com/brunoais/tampermonkey-editors/release/chrome/release/src/background/index.ts
203:35-47
[tsl] ERROR in /Users/1000060011/jb/github.com/brunoais/tampermonkey-editors/release/chrome/release/src/background/index.ts(203,36)
      TS2345: Argument of type 'ExtensionResponseMessage' is not assignable to parameter of type '(response?: any) => void'.
  Type 'WebSocketConnectResponse' is not assignable to type '(response?: any) => void'.
    Type 'WebSocketConnectResponse' provides no match for the signature '(response?: any): void'.

@derjanb
Copy link
Member

derjanb commented Dec 5, 2025

I asked @brunoais to add more types. Maybe this caused these errors. Can you try commit cbe6b5a please?

@jubr
Copy link

jubr commented Dec 5, 2025

Now it's back to only one error: TS6133: 'fail' is declared but its value is never read.

A quick fix 😋
Tnx for the tip!

@jubr
Copy link

jubr commented Dec 5, 2025

Yup, build suc6. Now firing it up....

@jubr
Copy link

jubr commented Dec 5, 2025

W00t @

image

and

image

@jubr
Copy link

jubr commented Dec 5, 2025

Note to self: clean up namespaces in my scripts 🙃

And now let's see if this speeds up my workflow with Cursor.... 🤞

@brunoais
Copy link
Author

brunoais commented Dec 5, 2025

Activity summons me.

In my case, I use firefox, so don't run that sed command. I can make it work simply by forging the id of the extension.

Given the large list of type errors, @jubr , if you know how to deal with typescript types, you are welcome to help. I'm a complete beginner with Typescript typing system.
I don't know how I didn't get any errors when I tried to compile some months ago but seems like it's no longer correct or it wasn't correct all along and I couldn't perceive it.

@jubr, if you may, I'd like feedback about the implementation on vscode side (not here but in its repo). I know about many issues with the extension but I want to know about potential fixes or alternative ways of solving its issues.

@brunoais
Copy link
Author

brunoais commented Dec 5, 2025

@brunoais Always feel free to ping me, in case my response takes too long... 🙈

I pinged you but I didn't insist because I didn't want to repeat the ping assuming that you couldn't come and you'd eventually come. I'll ping you about once a month when you don't respond, then.

@derjanb
Copy link
Member

derjanb commented Dec 8, 2025

@brunoais I created PR #16 which includes your changes and also fixes and improvements. I also added a simple Vue UI which should be easily tweakable. Please review. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Allow/document means so another addons can communicate to create/edit userscripts.

3 participants