0

*For better understanding see this screen: * https://ibb.co/982MWGB

I want to paste the copied HTML formatted content from my clipboard (that I copied through document.execCommand('copy') in chrome extension) on my browser window, that could be any active tab on the browser and it should be pasted in any input/textarea/rich editor at that range where I click my mouse.

Problem: I am not able to give controls to active tab and not able to paste copied HTML formatted content on my click.

In my case, I made a chrome extension where I have a list of users, so when I click on each user I get the HTML formatted content (not string) copied in clipboard using document.execCommand('copy'); I want this to be pasted in any input/textarea/rich editor where I click my mouse.

Manifest.json looks like

{
    "manifest_version": 2,
    "name": "ChromeExtension",
    "version": "1.0",
    "permissions": [
        "http://*/",
        "https://*/",
        "http://localhost/",
        "http://localhost/chromeextension/",
        "downloads",
        "activeTab",
        "declarativeContent",
        "storage",
        "tabs",
        "webNavigation",
        "notifications"
    ],
    "content_scripts": [{
        "matches": ["http://*/*", "https://*/*"]
    }],
    "content_scripts": [ {
        "matches": ["*://*/*"],
        "js": ["jquery.js", "quilljs.js", "popup.js"]
    }],
    "browser_action": {
        "default_icon": "icon.png",
        "default_title": "Custom Marketing Extension",
        "default_popup": "popup.html"
    },
    "background": {
        "scripts": ["background.js"],
        "persistent": true
    },
    "icons": {
        "16": "icon.png",
        "32": "icon.png",
        "48": "icon.png",
        "128": "icon.png"
    }
}

I want to be able to paste copied content in active tab in the browser window.

Aoun Raza
  • 13
  • 3
  • It's unclear what your code actually does so I'll comment on what I can currently **guess**. 1) You can probably use execCommand('paste'), but make sure to add the [clipboard permissions](https://developer.chrome.com/extensions/declare_permissions). 2) There seems to be a misunderstanding about the architecture. The popup is a separate window with its own document and DOM, not related to the web page. It means you need a separate content script file. That file will run in the web page, not in the popup. They can communicate via [messaging](https://developer.chrome.com/extensions/messaging). – wOxxOm Sep 03 '19 at 11:53
  • @wOxxOm Thanks I was able to achieve with chrome.tab event via message communication. Thanks – Aoun Raza Sep 11 '19 at 07:42

1 Answers1

0

Someone else has been able to use localsotrage across multiple tabs. Please see: browser sessionStorage. share between tabs?