Search code examples
google-chromegoogle-chrome-extension

How to host a chrome extension?


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 ?


Solution

  • 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.