Skip to content

Instantly share code, notes, and snippets.

@cvializ
Created May 12, 2016 00:18
Show Gist options
  • Save cvializ/dd2bc297c4f7280459d6dfa25ef6a6e4 to your computer and use it in GitHub Desktop.
Save cvializ/dd2bc297c4f7280459d6dfa25ef6a6e4 to your computer and use it in GitHub Desktop.
Reload an img tag's image data through an extension's background page.
function onExtensionImgError(e) {
var img = e.target;
var tagName = img.tagName.toLowerCase();
var wasReattempted = img.dataset.myExtensionReattempted;
var reattempt = (!wasReattempted && tagName === 'img' && isHttpUrl(img.src) && extensionContains(img));
if (reattempt) {
img.dataset.myExtensionReattempted = true;
api.port.emit('load_image', img.src, function onRespond(data) {
var err = data.error;
if (!err) {
img.src = data.uri;
} else {
console.log('[onExtensionImgError] Could not fix image: %s', err);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment