How to host a chrome extension?

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

I need to host my chrome extension on my shared hosting with PHP.

I know that my server must use appropriates HTTP headers: code.google.com/chrome/extensions/hosting.html

But, how to set my server to send these headers in addiction to .crx file ?

回答1:

If you are on a shared hosting and can't change server configuration, use PHP:

<?php $file = 'extension.crx';  if (file_exists($file)) {     header('Content-Description: File Transfer');     header('Content-Type: application/x-chrome-extension');     header('Content-Disposition: attachment; filename='.basename($file));     header('Content-Transfer-Encoding: binary');     header('Expires: 0');     header('Cache-Control: must-revalidate');     header('Pragma: public');     header('Content-Length: ' . filesize($file));     ob_clean();     flush();     readfile($file);     exit; } ?> 

source

This will force file (specified by $file variable) download with customized headers.



回答2:

I do not know what web server are you using, but for Apache you can do the following:

  1. vi /path/to/your/httpd/conf/mime.types
  2. Add this line: application/x-chrome-extension crx at the end of the file
  3. Restart your webserver: killall -HUP httpd

Or you can try adding this line to your .htaccess file:

AddType application/x-chrome-extension crx 

And it should work!



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!