Skip to content

Commit 3146691

Browse files
committed
file://プロトコル処理にtry-catchを追加
1 parent 2a7ddc6 commit 3146691

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

js/kunai.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,23 @@ class Kunai {
152152
// HTML in a local file system is directly opened in a Web browser,
153153
// "static/crsearch/crsearch.json" cannot be read using XHR due to the
154154
// CORS (cross-origin resource sharing) policy for the local files.
155-
if (/^file:\/\//.test(current_script.src)) {
156-
const url_kunai = current_script.getAttribute("src")
157-
158-
// When the current script file (kunai.js) is located in an expected
159-
// path in the tree, we try to load the local database file
160-
// "crsearch/crsearch.js" in JSONP format.
161-
const url = url_kunai.replace(/\bkunai\/js\/kunai\.js([?#].*)?$/, "crsearch/crsearch.js")
162-
if (url != url_kunai) return url
163-
164-
// Try to download "crsearch.json" from the project website.
165-
if (online_base_url)
166-
return online_base_url + "static/crsearch/crsearch.json"
155+
try {
156+
if (/^file:\/\//.test(current_script.src)) {
157+
const url_kunai = current_script.getAttribute("src")
158+
159+
// When the current script file (kunai.js) is located in an expected
160+
// path in the tree, we try to load the local database file
161+
// "crsearch/crsearch.js" in JSONP format.
162+
const url = url_kunai.replace(/\bkunai\/js\/kunai\.js([?#].*)?$/, "crsearch/crsearch.js")
163+
if (url != url_kunai) return url
164+
165+
// Try to download "crsearch.json" from the project website.
166+
if (online_base_url)
167+
return online_base_url + "static/crsearch/crsearch.json"
168+
}
169+
} catch (e) {
170+
this.log.warn('Failed to handle file:// protocol:', e)
171+
// フォールバックとして通常のURLを使用
167172
}
168173

169174
// Try to determine the position of crsearch.json

0 commit comments

Comments
 (0)