Web Core CopyToClipboard


When using the TWebClipBoard component, I get an error when trying to use the CopyToClipboard command.

This is the only piece of code regarding the TWebClipBoard component:

procedure BtnCopyThreadLinkClick(Sender: TObject);
    Tcp: TWebClipBoard;
    Tcp.CopyToClipboard(Application.EXEName +'?ViewThread=' +AObject.GetJSONValue('Thread_ID'));

Now, when running this in localhost I get no error. But when deploying the project to the IIS, I get the following error in Google Chrome:

Uncaught TypeError: Cannot read property 'writeText' of undefined
at Object.rtl.module.rtl.createClass.CopyToClipboard (Cucuvi.js?ver=1.3:1)
at Object.g.FOnClick (Cucuvi.js?ver=1.3:1)
at Object.rtl.module.rtl.createClass.Click (Cucuvi.js?ver=1.3:1)
at Object.rtl.module.rtl.createClass.HandleDoClick (Cucuvi.js?ver=1.3:1)
at HTMLButtonElement.i (Cucuvi.js?ver=1.3:1)

In Firefox, the error is as follows:

Uncaught TypeError: window.navigator.clipboard is undefined
CopyToClipboard http://cucuvisrv/Cucuvi.js?ver=1.3:1
FOnClick http://cucuvisrv/Cucuvi.js?ver=1.3:1
Click http://cucuvisrv/Cucuvi.js?ver=1.3:1
HandleDoClick http://cucuvisrv/Cucuvi.js?ver=1.3:1
i http://cucuvisrv/Cucuvi.js?ver=1.3:1

What might be the reason/solution to this problem?

Kind regards.


TWebClipBoard.CopyToClipboard uses the Async Clipboard API which requires secure context. From your error messages it seems like you are using HTTP instead of HTTPS.