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:
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