Created
May 12, 2016 00:18
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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