Nameless icon indicating copy to clipboard operation
Nameless copied to clipboard

Change copy function to Clipboard API

Open PadowYT2 opened this issue 3 years ago • 4 comments

As the execCommand is deprecated and not recommended, this is a remake of it. Simple, small, also used in

https://github.com/NamelessMC/Nameless/blob/848a2e33af959ce8cc59b70a5a0e3614706352d7/error.tpl#L384

PadowYT2 avatar Aug 14 '22 14:08 PadowYT2

navigator only exists when HTTPS is enabled, so this will not work on HTTP only sites

tadhgboyle avatar Aug 17 '22 20:08 tadhgboyle

navigator only exists when HTTPS is enabled, so this will not work on HTTP only sites

But then even, should we remove it from error.tpl or what?

PadowYT2 avatar Aug 18 '22 05:08 PadowYT2

No, as you can see in the error.tpl file we check that it [navigator] is not undefined first, and then use it if it exists. Otherwise it falls back to the other way

On Wed, Aug 17, 2022 at 23:46 PadowYT2 @.***> wrote:

navigator only exists when HTTPS is enabled, so this will not work on HTTP only sites

But then even, should we remove it from error.tpl or what?

— Reply to this email directly, view it on GitHub https://github.com/NamelessMC/Nameless/pull/3028#issuecomment-1219062984, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGG43DCTT3BIHLVWGXUAGJ3VZXE4PANCNFSM56P5PAJA . You are receiving this because you commented.Message ID: @.***>

tadhgboyle avatar Aug 18 '22 05:08 tadhgboyle

Should we be using deprecated functions at all? I have seen sites do something like this instead:

if (window.isSecureContext) {
    navigator.clipboard.writeText(url);
    // Display "URL copied to clipboard" toast
} else {
    // Create popup or toast with the URL, with a message that it should be copied manually
}

Derkades avatar Aug 18 '22 08:08 Derkades

Looks like there are some other places in the codebase that still use execCommand, if you could fix all of those, and use Derks suggestion of window.isSecureContext instead of navigator.clipboard !== undefined, that would be great.

tadhgboyle avatar Sep 30 '22 00:09 tadhgboyle

Being done in new PR alongside other changes

tadhgboyle avatar Sep 30 '22 04:09 tadhgboyle