0

I want to right click inside a webpage frame (iframe) and copy it's URL to the clipboard.

I found this very simple extension and started modifying it:

https://chrome.google.com/webstore/detail/this-frame/kojdncoigaceddhffgjhpmfnblpgabmj/related?hl=en-US

I added a new context option "Copy URL" (although i would like to move it to the main context later rather than a sub-menu) but i have a problem with the variable "frameUrl" to be copied to the clipboard.

Example:

chrome.contextMenus.onClicked.addListener(function (info, tab)
{
    let frameUrl = info.frameUrl;

    switch (info.menuItemId) {
        case MenuItemIDs.NEW_TAB:
            chrome.tabs.create({
                windowId: tab.windowId,
                index: tab.index + 1,
                url: frameUrl,
                openerTabId: tab.id
            });
            break;
        case MenuItemIDs.NEW_WINDOW:
            chrome.windows.create({
                url: frameUrl,
                incognito: tab.incognito,
                state: 'maximized'
            });
            break;
        case MenuItemIDs.SHOW_URL:
            prompt(chrome.i18n.getMessage('show_url_dialog'), frameUrl);
            break;
        case MenuItemIDs.COPY_URL:
            frameUrl.select();  
            document.execCommand("copy");
            break;          
    }
});

This is the case i added:

        case MenuItemIDs.COPY_URL:

I've tried several things but the only thing i've managed is for it to copy "frameUrl" as a text in the clipboard and not the actual URL contained inside this variable.

What am i am doing wrong? My guess frameUrl is not a simple variable but something else

desertnaut
  • 57,590
  • 26
  • 140
  • 166
TnF
  • 21
  • 1
  • 6

1 Answers1

0

I found this solution that works from this BOSS here:

https://stackoverflow.com/a/51126086/4844537

Turns out accessing the clipboard is a total clusterf*ck due to security reasons, and requires the form of a user input.

TnF
  • 21
  • 1
  • 6