Basically I'm trying to copy data from <input>
s on one tab and then paste it into a form <input>
s on another tab using a chrome extension.
The part that I'm having trouble with figuring out is how to transfer the data from one tab to the other and how to target the right tabs.
Copying data from the form inputs is just a simple document.getElementById()
, I created a content.js that runs on the current tab when the extension icon is clicked.
Manifest
{
"name": "AnalystWizard",
"version": "1.0",
"manifest_version": 2,
"description": "Helping analysts since 2016",
"background" : {
"scripts" : ["background.js"]
},
"permissions": [
"tabs", "<all_urls>"
],
"browser_action": {
"default_icon": "icon.png"
}
}
Background.js
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(null, {file: "content.js"});
});
Content.js
var name = document.getElementById("fname").value;
var street = document.getElementById("street").value;
var state = document.getElementById("state").value;
At this point the necessary data is stored within the name
, street
, and state
variables. This is where I'm having trouble. Once I have the data stored in variables, how can I tell my extension to allow the user to target a new tab? The inserting of the data I can just do the same as above but reversed.
New tab:
document.getElementById("form1_name").value = name;
document.getElementById("form1_street").value = street;
document.getElementById("form1_state").value = state;
Perhaps there's a way I can use a popup.html
from my extension that will have two buttons, one labeled source
that will scrape the data on the current tab, then the user will change to the tab they want to paste, and the second button as destination
that will input the data on the newly active tab?