I setup this layout for an extension I am trying to build to make my work easier.
manifest.json
{
"manifest_version": 2,
"name": "Work Order Dispatcher",
"version": "0.1",
"description": "Work order dispatcher for BeHome/v12",
"background": {
"persistent": false,
"scripts": ["background.js"]
},
"content_scripts": [{
"matches": ["*://*.v12.instantsoftware.com/*"],
//"matches": ["www"],
"js": ["content.js"]
}],
"browser_action": {
"default_title": "Work Order Dispatcher"
},
"permissions": [
"activeTab"
]
}
Background.js
// Regex-pattern to check URLs against.
// It matches URLs like
//var urlRegex = /^https?:\/\/(?:[^./?#]+\.)?v12.instantsoftware\.com/;
var urlRegex = /^https?:\/\/(?:[^./?#]+\.)?v12\.instantsoftware\.com/;
// A function to use as callback
function doStuffWithDom(domContent) {
console.log('I received the following DOM content:\n' + domContent);
}
// When the browser-action button is clicked...
chrome.browserAction.onClicked.addListener(function (tab) {
// ...check the URL of the active tab against our pattern and...
if (urlRegex.test(tab.url)) {
// ...if it matches, send a message specifying a callback too
chrome.tabs.sendMessage(tab.id, {text: 'report_back'}, doStuffWithDom);
}
});
content.js
// Listen for messages
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
// If the received message has the expected format...
if (msg.text === 'report_back') {
// Call the specified callback, passing
// the web-page's DOM content as argument
sendResponse(document.getElementsByTagName('body'));
}
});
I am trying to pull data from a text field on a website and insert it in another text field on a different website. I use the two sites side by side. In my console I get:
4background.js:8 I received the following DOM content:
undefined
I think it is only pulling the background DOM of the extension itself?
I guess the confusion comes in at would I be able to store the content of a dom item and place it into an HTML text area of my own (which I have yet to build) and then be able to send that off to my other website so I can dispatch my guys. Let me know if you need more details about what I am trying to accomplish.
Thanks in advance.