You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mount and unmount Content Script UI with MutationObserver #537
However, this div can be removed following certain actions on the page. I would need to reassemble my component as soon as this div reappears. How can I do this?
You'll want to use the awaited element as the anchor tag, and use the append option to append your UI using insertAdjacentElement.
Something like this would work. I typed this up in github comments, so it probably isn't valid JS, and I haven't tested it. But hopefully it gives you a better idea of what you're looking for.
Thank you very much for this issue. I have recently encountered a similar problem.
I want to inject content script above a specific div on the website after it has loaded.
I have tried the methods, which are effective. Thanks for @aklinker1 .
I wonder if there are other methods that can achieve similar functions? Maybe similar effects can be achieved without using an anchor?
I've been thinking about this Issue in the back of my mind for a long time. We get a lot of questions about dynamic UI mounts.
I just wonder what and how WXT should support. I have a feeling that autoMount will have a lot of responsibility since the timing and conditions are different for each application.
BTW: Actually, I have a personal library for dynamic mounting, lol.
I have a feeling that autoMount will have a lot of responsibility since the timing and conditions are different for each.
Hmm, I recommended this function to addressing a single use case: mounting a UI inside a dynamic element that gets added and removed.
If someone wants a custom implementation, like listening to focus events, or adding timeouts, they should write those themselves using ui.mount and ui.unmount. that's why we provide those APIs.
BTW: Actually, I have a personal library for dynamic mounting, lol.
Nice! We can probably use it, does it support listening for when the element is removed from the DOM?
If someone wants a custom implementation, like listening to focus events, or adding timeouts, they should write those themselves using ui.mount and ui.unmount. that's why we provide those APIs.
If you are set in your mind on that policy, it's ok 👍 . Writing in the document that it is a single use case would avoid confusion users.
does it support listening for when the element is removed from the DOM?
Supported by detector option. However, this library doesn't manage DOM state. This is an async wrapper for pure mutationObserver and querySelector. So if you want accuracy based on DOM state, will need a separate DOM state manager.
Basically, it goes like this. (recently, major bump to v4, so if there any bugs it might not work properly 😅 )
Yeah, I’m willing to take this. I recently made my library support xpath for this issue :). I'm trying to write the test code first……but recently I've been so busy that I haven't had time. Need more time.
@aklinker1 I'm working on the implementation a bit at a time. So we need to some decisions about the specs. About once option API, is this “only one mount” or “one mount and one remove”? Which did you expect?
And I think about the StopAutoMount, should be stopped when ui.remove is called, is there any discrepancy?
Activity
aklinker1 commentedon Mar 10, 2024
You'll want to use the awaited element as the
anchortag, and use theappendoption to append your UI usinginsertAdjacentElement.Something like this would work. I typed this up in github comments, so it probably isn't valid JS, and I haven't tested it. But hopefully it gives you a better idea of what you're looking for.
[-]Mount and unmount with MutationObserver[/-][+]Mount and unmount Content Script UI with MutationObserver[/+]aklinker1 commentedon Mar 12, 2024
@hexpl0it If you get something that works, I'd like to add auto-mounting/unmounting to WXT, if you would like to contribute your implementation.
tesths commentedon May 12, 2024
Thank you very much for this issue. I have recently encountered a similar problem.
I want to inject content script above a specific div on the website after it has loaded.
I have tried the methods, which are effective. Thanks for @aklinker1 .
I wonder if there are other methods that can achieve similar functions? Maybe similar effects can be achieved without using an
anchor?aklinker1 commentedon Sep 24, 2024
Think I'm gonna work on this soon. Here's what I'm thinking the API will look like:
Here's the types I expect:
1natsu172 commentedon Sep 25, 2024
I've been thinking about this Issue in the back of my mind for a long time. We get a lot of questions about dynamic UI mounts.
I just wonder what and how WXT should support. I have a feeling that
autoMountwill have a lot of responsibility since the timing and conditions are different for each application.BTW: Actually, I have a personal library for dynamic mounting, lol.
aklinker1 commentedon Sep 25, 2024
Hmm, I recommended this function to addressing a single use case: mounting a UI inside a dynamic element that gets added and removed.
If someone wants a custom implementation, like listening to focus events, or adding timeouts, they should write those themselves using
ui.mountandui.unmount. that's why we provide those APIs.Nice! We can probably use it, does it support listening for when the element is removed from the DOM?
1natsu172 commentedon Sep 25, 2024
If you are set in your mind on that policy, it's ok 👍 . Writing in the document that it is a single use case would avoid confusion users.
Supported by
detectoroption. However, this library doesn't manage DOM state. This is an async wrapper for puremutationObserverandquerySelector. So if you want accuracy based on DOM state, will need a separate DOM state manager.Basically, it goes like this. (recently, major bump to v4, so if there any bugs it might not work properly 😅 )
aklinker1 commentedon Nov 12, 2024
I am onboard with adding functionality to WXT.
1natsu172 commentedon Nov 13, 2024
Yeah, I’m willing to take this. I recently made my library support xpath for this issue :). I'm trying to write the test code first……but recently I've been so busy that I haven't had time. Need more time.
sgcullen commentedon Nov 21, 2024
Interesting discussion - I'm doing similar stuff - following :-)
1natsu172 commentedon Nov 21, 2024
@aklinker1 I'm working on the implementation a bit at a time. So we need to some decisions about the specs. About
onceoption API, is this “only one mount” or “one mount and one remove”? Which did you expect?And I think about the
StopAutoMount, should be stopped whenui.removeis called, is there any discrepancy?aklinker1 commentedon Nov 21, 2024
I would expect it to be mounted and removed once.
Yes, I agree with you on that. Calling
ui.remove()should stop the auto-mount watcher as well.1natsu172 commentedon Nov 21, 2024
Okay, I'll go ahead with those specs for both!
aklinker1 commentedon Dec 9, 2024
Release in
v0.19.20: https://wxt.dev/guide/essentials/content-scripts.html#mounting-ui-to-dynamic-element