Skip to content

Instantly share code, notes, and snippets.

@aoirint
Last active December 2, 2022 23:02
Show Gist options
  • Save aoirint/c47a5908490fbca4db441b55eee3ee51 to your computer and use it in GitHub Desktop.
Save aoirint/c47a5908490fbca4db441b55eee3ee51 to your computer and use it in GitHub Desktop.
Chrome拡張機能で、VOICEVOX ENGINE宛のリクエストからOriginヘッダを削除するスニペット。VOICEVOX 0.14からエンジンにCORSやOrigin検査が入る予定なので、その対策。Chrome v96 - v108までは動作するはず...(v109以降で動作する・推奨の書き方であるとは限らない)。開発バージョン: Google Chrome 108, VOICEVOX ENGINE 0.14.0-preview.4
chrome.declarativeNetRequest.updateDynamicRules({
removeRuleIds: [1],
addRules: [
{
id: 1,
priority: 1,
action: {
type: 'modifyHeaders',
requestHeaders: [
{ 'header': 'Origin', 'operation': 'remove' },
],
},
condition: {
urlFilter: '127.0.0.1:50021/*',
initiatorDomains: [chrome.runtime.id], // chrome-extension://{extension_id}
},
},
],
})
{
"manifest_version": 3,
"name": "example-voicevox-extension",
"version": "0.1.0",
"description": "",
"icons": {
"128": "assets/icon128.png"
},
"permissions": [
"declarativeNetRequestWithHostAccess"
],
"host_permissions": [
"http://127.0.0.1:50021/*"
],
"background": {
"service_worker": "src/background.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment