How to paste custom (variable) text using webView?

How do you paste custom text from a variable in js?

Using the copy to json function for paste text, the string is turned into a string of characters (some kind of encoding?), "Why" becomes: "BAtzdHJlYW10eXBlZIHoA4QBQISEhA1OU1RleHRTdG9yYWdlAISEGU5TTXV0YW..."

Replacing this string with a normal text string results in nothing being pasted using

callBTT('trigger_action', json: {..., 
  "BTTAdditionalActionData": {
    "BTTActionTextToPaste": "Why"

Is there a better way to paste text to another application than using this method? If not, how do you encode text to this format?

1 Like

Ah this is indeed a bit complicated because the BTTActionTextToPaste transforms its content to richtext and then base64 encodes it (so it can also paste bold/with colors etc.)

There is an undocumented way how you can paste plain text though:

(async ()=> {



You can also use the BTTActions.pasteString('test'); directly in a BTT webview


Thanks Andreas! Amazing response time as always

Hi Andreas,

I tried using BTTActions.pasteString('test'); in a web view like this:

async function PasteTest() {

However, I get this error message in the console:

Unhandled Promise Rejection : ReferenceError: Can't find variable: BTTActions

What am I missing?


Try calling the function in this:

/* This is called after the webview content has loaded*/
function BTTInitialize() {

Thanks for the quick reply. Here's what I tried:


  .wrapper {
    display: grid;
    grid-template-columns: 100px 100px 100px;
    grid-gap: 10px;
    color: #444;

  .box {
    background-color: #444;
    color: #fff;
    border-radius: 5px;
    font-size: 12px;
    text-decoration: none;

  .box:hover {
      background: red;

  #status {
    color: red;
    font-weight: bold;

/* This is called after the webview content has loaded*/
function BTTInitialize() {

async function PasteTest() {

function closeTheWebView() {
  // every callBTT() function does close the webview as long as it contains the closeFloatingWebView:1 parameter
  callBTT('trigger_named', {trigger_name: '', closeFloatingWebView:1});

<!-- adding BTTDraggable to an element will allow you to drag the window when dragging it -->
<div class="wrapper BTTDraggable">
  <div class="box b" onclick="PasteTest()">GL</div>
  <div class="box b" onclick="closeTheWebView()">Fermer</div>

I got the same error (see attached image)

Do I have to include any script file in my html file?

Best regards

I’m unable to look into it before tomorrow, but will try there if it’s still causing problems.

Any chance this is from a browser, not the webview?

Also make sure you are using a recent BTT version. The BTTActions object has not always been there.
And as @mattorp said, this will only work inside BTT floating html/webviews


I'm using version 3.402 (1633) on Catalina 10.15.6.

Here a copy of the trigger used to show my webview :

    "BTTTouchBarButtonName" : "copy",
    "BTTTriggerType" : 629,
    "BTTTriggerTypeDescription" : "Touch Bar button",
    "BTTTriggerClass" : "BTTTriggerTypeTouchBar",
    "BTTPredefinedActionType" : 249,
    "BTTPredefinedActionName" : "Show Floating WebView\/HTML Menu",
    "BTTActionURLToLoad" : "\/Users\/etiennerivard\/Dropbox\/Apps\/BetterTouchTool\/html\/gl.html",
    "BTTActionFloatingHTMLName" : "GL",
    "BTTActionFloatingHTMLConfig" : "{\"BTTSize\":\"{200, 200}\",\"BTTShowAboveDesktop\":0,\"BTTCloseOnBrowserOpen\":false,\"BTTUseWhiteBackground\":true,\"BTTCenterOnOpen\":false,\"BTTFrameOrigin\":\"{0, 0}\",\"BTTUseFixedPosition\":false,\"BTTWebviewDragEverywhere\":false,\"BTTCloseOnOutsideClick\":false,\"BTTWebviewResizable\":false,\"BTTWebviewDragEverywhereCMD\":false,\"BTTShowButtons\":false,\"BTTRelativeTo\":0,\"BTTWebViewShowDockIcon\":0,\"BTTWebviewUpdateFrame\":false,\"BTTDoNotCache\":true,\"BTTWebViewManualWindowLevel\":0,\"BTTDrawTitleBezel\":false}",
    "BTTEnabled2" : 1,
    "BTTRepeatDelay" : 0,
    "BTTUUID" : "81FD309C-5AC6-4B7C-90B3-6DC20B45CBFB",
    "BTTNotesInsteadOfDescription" : 0,
    "BTTEnabled" : 1,
    "BTTModifierMode" : 0,
    "BTTOrder" : 10,
    "BTTDisplayOrder" : 0,
    "BTTMergeIntoTouchBarGroups" : 0,
    "BTTTriggerConfig" : {
      "BTTTouchBarButtonColor" : "75.323769, 75.323769, 75.323769, 255.000000",
      "BTTTouchBarItemIconWidth" : 22,
      "BTTTouchBarButtonTextAlignment" : 0,
      "BTTTouchBarButtonFontSize" : 15,
      "BTTTouchBarAlternateBackgroundColor" : "75.323769, 75.323769, 75.323769, 255.000000",
      "BTTTouchBarItemPlacement" : 0,
      "BTTTouchBarAlwaysShowButton" : false,
      "BTTTBWidgetWidth" : 400,
      "BTTTouchBarIconTextOffset" : 5,
      "BTTTouchBarButtonWidth" : 100,
      "BTTTouchBarOnlyShowIcon" : false,
      "BTTTouchBarFreeSpaceAfterButton" : 5,
      "BTTTouchBarButtonName" : "copy",
      "BTTTouchBarItemIconHeight" : 22,
      "BTTTouchBarItemPadding" : 0

Is there a debug mode in BTT to help me find the missing piece to this puzzle?


I don't know if it could help but I can see some errors in console for the process:

error	21:46:25.107666-0400	0 is not a valid connection ID.

It comes from the PID associated to the BetterTouchTool Web Content process.


Hey, I'm having the same issue. I would like to save the currently highlighted/selected text as a variable and access it using the javascript inside of my webview popup. Have you found a solution?