Skip to content

Attempt to restore Tridactyl if document.open, write or writeln are called#5261

Draft
Chic-Tweetz wants to merge 7 commits into
tridactyl:masterfrom
Chic-Tweetz:document.write-hijack
Draft

Attempt to restore Tridactyl if document.open, write or writeln are called#5261
Chic-Tweetz wants to merge 7 commits into
tridactyl:masterfrom
Chic-Tweetz:document.write-hijack

Conversation

@Chic-Tweetz
Copy link
Copy Markdown
Contributor

@Chic-Tweetz Chic-Tweetz commented Sep 9, 2025

Regarding #5259.

Some sites use the (deprecated) document.open / document.write / document.writeln functions which create entirely new document objects. Event listeners and elements are consequently lost.

This hijacks those functions to dispatch an event call an exported function before the document is replaced, allowing us to readd listeners, the commandline and status indicator.

I'm not sure that I've found every listener which needs re-listening.

This also assumes that document.close will be promptly called, as that's when everything will be readded.

@bovine3dom
Copy link
Copy Markdown
Member

bovine3dom commented Sep 11, 2025

Thanks. One thing that is making me nervous is that we need to remember to put any future things we add to the page within this wrapper.

Is there any kind of function we can make that wraps such calls and adds them to a kind of registry so that they get readded?

then some linting rules to make sure we call that function?

edit: i guess the wrapper would need to run at transpile time just in case the page got killed before they could first be called?

@Chic-Tweetz
Copy link
Copy Markdown
Contributor Author

Chic-Tweetz commented Sep 11, 2025

Yeah I initially just wanted to call the existing listen function and realised there's quite a lot more listening to do. I'm not sure I've added everything that already exists, let alone future additions.

A registry sounds good, most of the listening functions could be simply looped through and called. Readding the styles is a bit of a special case because they're originally inserted as part of the content script. I suppose the command line and status indicator could be added to a sort of element registry too?

You're right that it won't work if the page is killed too soon... or would the whole content script just run blissfully unaware there was a document that died before? I'm not sure actually. Is there anything else in Tridactyl that has to run at transpile time?

@bovine3dom
Copy link
Copy Markdown
Member

bovine3dom commented Sep 13, 2025

Is there anything else in Tridactyl that has to run at transpile time?

yeah, the compiler/ folder which gives us type checking at runtime for :set and type conversion for ex-commands.

it is more or less witchcraft, if it's too tricky we can just do it runtime like you're doing at the moment

edit:

I suppose the command line and status indicator could be added to a sort of element registry too?

yeah, this is the sort of thing i was thinking about

@bovine3dom
Copy link
Copy Markdown
Member

somehow this PR seems to break interaction with Tridactyl (e.g. j/k) on https://www.opensourcealternative.to/alternativesto/davinci-resolve (and presumably other next-js/react sites)

which is the opposite of what I was expecting :) I thought maybe there was a small chance it would fix the commandline issue.

@Chic-Tweetz
Copy link
Copy Markdown
Contributor Author

oh dang really? I've been using a build with this PR (from before I added the basic registry stuff) and the changes from #5260 and it's still working for me. I may have broken something with those registry functions (I don't think I meant to push that yet actually...)

@bovine3dom
Copy link
Copy Markdown
Member

i was surprised too - enough to check it three times :)

I can try bisecting it when I get a chance but it's probably just your registry commits from what you're saying

@Chic-Tweetz Chic-Tweetz force-pushed the document.write-hijack branch from 8764b11 to faeebd8 Compare October 1, 2025 13:37
@Chic-Tweetz Chic-Tweetz force-pushed the document.write-hijack branch from faeebd8 to 1b695c7 Compare October 1, 2025 13:43
@Chic-Tweetz
Copy link
Copy Markdown
Contributor Author

Chic-Tweetz commented Oct 1, 2025

I believe a conflict removed the lines which added the listener in content.ts to actually get the fix to work.

In my haste I made an absolute mess with the commits here. I don't think this PR wants to try and change every file in the world now and #5260 should work again.


I should note that although the registry functions exist, I haven't added any linter rules or made it clear what they're for. I'll change this to a draft for now :)

@Chic-Tweetz Chic-Tweetz marked this pull request as draft October 1, 2025 14:00
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.

2 participants