Skip to content

Instantly share code, notes, and snippets.

@jeffgca
Created June 23, 2014 18:32
Show Gist options
  • Save jeffgca/6c299c812bbe582d9efb to your computer and use it in GitHub Desktop.
Save jeffgca/6c299c812bbe582d9efb to your computer and use it in GitHub Desktop.
page-workr scraping example
let { Page } = require('sdk/page-worker');
let self = require('sdk/self');
let { ActionButton } = require("sdk/ui/button/action");
let worker = Page({
contentScriptFile: [self.data.url('worker.js'),
self.data.url('jquery.js')]
});
worker.on('fetched', function(data) {
// do something with the data
});
// a basic button to trigger the fetch command.
let button = ActionButton({
id: "my-button",
label: "my button",
icon: {
"16": "./firefox-16.png",
"32": "./firefox-32.png"
},
onClick: function(state) {
worker.port.emit('fetch');
}
});
$(function() {
self.port.on('fetch', function() {
// use jQuery to extract some data
var something = $('.classname').html();
// the data you send can only be arrays, text, numbers, not a whole jQuery result
self.port.emit('fetched', something);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment