在 Chrome 扩展中为图书馆的资源设置正确的路径
Setting correct path for libraries' resources in Chrome extension
如果我在开发 Chrome 扩展时使用了一些外部库,其资源的相对路径被解释为相对于当前页面,而不是扩展文件夹,这显然会导致 404。以 CKEditor 为例例如:
GET http://www.mywebsite.com/mypage/config.js?t=F0RD
ckeditor.js:77
GET http://www.mywebsite.com/mypage/skins/moono/editor.css?t=F0RD
ckeditor.js:77
GET http://www.mywebsite.com/mypage/lang/pt-br.js?t=F0RD
ckeditor.js:220
Uncaught TypeError: Cannot set property 'dir' of undefined
如何将路径设置到正确的位置?
据我所知没有 "global" 解决方案。
查看您的图书馆是否有基本浴配置选项。如果没有,您将不得不重写所有路径以使用 chrome.runtime.getURL()
(如果可能)或该路径的静态版本。
特别是对于 CKEditor,这应该有所帮助:Specifying the Editor Path
// Set this variable before loading CKEditor JS
// Replace "" with a subfolder if needed
var CKEDITOR_BASEPATH = chrome.runtime.getURL("");
如果我在开发 Chrome 扩展时使用了一些外部库,其资源的相对路径被解释为相对于当前页面,而不是扩展文件夹,这显然会导致 404。以 CKEditor 为例例如:
GET http://www.mywebsite.com/mypage/config.js?t=F0RD
ckeditor.js:77
GET http://www.mywebsite.com/mypage/skins/moono/editor.css?t=F0RD
ckeditor.js:77
GET http://www.mywebsite.com/mypage/lang/pt-br.js?t=F0RD
ckeditor.js:220
Uncaught TypeError: Cannot set property 'dir' of undefined
如何将路径设置到正确的位置?
据我所知没有 "global" 解决方案。
查看您的图书馆是否有基本浴配置选项。如果没有,您将不得不重写所有路径以使用 chrome.runtime.getURL()
(如果可能)或该路径的静态版本。
特别是对于 CKEditor,这应该有所帮助:Specifying the Editor Path
// Set this variable before loading CKEditor JS
// Replace "" with a subfolder if needed
var CKEDITOR_BASEPATH = chrome.runtime.getURL("");