'Chrome extension API How to copy variable into clipboard?

I'm making a Chrome extension in V3. I try to get all Google cookies. It works fine and I can successfully write it to the console using console.log(). What I want to do is this: copy all the cookies that I got from chrome.cookies.getAll() into the user clipboard. How can I do this?

manifest.json:

{
  "name": "test",
  "manifest_version": 3,
  "version": "1",

  "background": {
    "service_worker": "background.js"
  },

  "host_permissions": [
    "*://*.google.com/*"
  ],

  "permissions": [
    "cookies"
  ]
}

background.js:

function test()
{
    chrome.cookies.getAll({
    }, function (theCookies) {
        cookies = theCookies
        console.log(cookies)
    });
}

test();


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source