Avoid injecting script to unrelated sites (#665)

* Avoid injecting script to unrelated sites

* unnecessary comment
This commit is contained in:
Nguyễn Kim Kha 2020-05-26 13:17:35 +10:00 committed by GitHub
parent ad1afe9b63
commit e33f019c1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -348,6 +348,9 @@ extensionApi.webRequest.onBeforeSendHeaders.addListener(function (details) {
}
if (tabId !== -1) {
extensionApi.tabs.get(tabId, function (currentTab) {
// Validate url of current tab to avoid injecting script to unrelated sites
if (currentTab && isSiteEnabled(currentTab)) {
// run contentScript inside tab
extensionApi.tabs.executeScript(tabId, {
file: 'src/js/contentScript.js',
@ -358,6 +361,8 @@ extensionApi.webRequest.onBeforeSendHeaders.addListener(function (details) {
}
});
}
});
}
return { requestHeaders: requestHeaders };
}, {