$livewire->dispatchBrowserEvent('copy-to-clipboard') is not working on Safari
I have a header action that dispatches the 'copy-to-clipboard' event to the browser. However this is known to not work on Safari. There are workarounds using Javascript, but I don't know how to implement them with Filament. Do you guys have a suggestion?
7 Replies
Have you found a workaround that you want to implement? An external JS library or something?
Yes I found it on StackOverflow (https://stackoverflow.com/questions/40147676/javascript-copy-to-clipboard-on-safari). There are multiple suggested implementations on this post.
Stack Overflow
Javascript Copy To Clipboard on safari?
It may be duplicate question but i didnt find the solution for this.
I am trying to copy text on button click. Its working on chrome, mozilla(working on on windows and mac but not on linux). And i...
Which solution do you want to try? What are you missing to make it work in Filament?
The second suggestion says that Safari implemented the Clipboard API 1 year ago. Which requires a small amount of javascript code:
What I am missing is how do I execute this piece of javascript code in the action of the table. This the stripped done table I currently have:
Because this table is inside a RelationManager class, which is used inside a Resource. This Resource is used inside a ListRecords class. But there is no associated blade file (or I cannot find it) where I can use a script tag to execute the javascript. I don't see a way to actually execute the Javascript, which is the main question I have. Do you know a way to execute this piece of Javascript?
Ok, makes sense. I think I can give you an idea you can experiment with...
Create a custom JS file to load into your Filament Admin:
Register the script in your
AppServiceProvider
:
Then, you can dispatch the event normally, from the Table Action:
Thanks @pboivin, I am able to import the JS! The clipboard functionality still doesn't work on Safari though. I tried every solution from StackOverflow. Could be out of the scope of Filament, but I'm not sure.
I have no real experience with Safari unfortunately...