Skip to content

Instantly share code, notes, and snippets.

@bobsilverberg
Created June 30, 2016 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobsilverberg/cb1529a0d4cfcb4890eeefe5efe29802 to your computer and use it in GitHub Desktop.
Save bobsilverberg/cb1529a0d4cfcb4890eeefe5efe29802 to your computer and use it in GitHub Desktop.
// Alias several messaging deprecated APIs to their runtime counterparts.
var mayNeedAlias = [
// Types
'Port',
// Functions
'connect', 'sendMessage', 'connectNative', 'sendNativeMessage',
// Events
'onConnect', 'onConnectExternal', 'onMessage', 'onMessageExternal'
];
$Array.forEach(mayNeedAlias, function(alias) {
// Checking existence isn't enough since some functions are disabled via
// getters that throw exceptions. Assume that any getter is such a function.
if (chrome.runtime &&
$Object.hasOwnProperty(chrome.runtime, alias) &&
chrome.runtime.__lookupGetter__(alias) === undefined) {
extension[alias] = chrome.runtime[alias];
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment