An HTTP Web Server for Chrome (chrome.sockets API)

Overview

Try it now in CWS

Web Server for Chrome

an HTTP web server for Chrome (chrome.sockets)

Get it in the chrome web store: https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb

Many people have found the webstore version useful for doing some basic web development as an alternative to python -m SimpleHTTPServer. But it can also be used for quick file sharing over a local network.

Features

  • serve local files
  • configure listening port
  • configure listening interface (e.g. localhost or all interfaces)
  • custom http handlers possible
  • websocket support available
  • works nice with chrome.runtime.onSuspend
  • options for autostart, start in background, etc etc.
  • handles range requests, HEAD, etc
  • options for CORS
  • optional PUT, DELETE request (for upload files)
  • sets MIME types
  • can render directory listing
  • See relevant options: https://github.com/kzahel/web-server-chrome/blob/master/polymer-ui/options.js

How to include into your own chrome app

run minimize.sh to concatenate all the required files together and then include the resulting wsc-chrome.min.js in your project. Here is an example of another project's usage: https://github.com/zebradog/kiosk/blob/f7a398f697edc1c22b90c14f959779f1e850012a/src/js/main.js#L124

Basic usage:

var app = new WSC.WebApplication(options)
app.start( callback )

options: object, with keys

Handlers
    var handlers = [
        ['/favicon.ico',FavIconHandler],
        ['/stream.*',StreamHandler],
        ['/static/(.*)',StaticHandler],
        ['.*', DefaultHandler]
    ]

handlers is an array of 2 element arrays where the first item is a regular expression for the URL and the second is the handler class, which should extend WSC.BaseHandler

    function StaticHandler() {
        this.disk = null
        chrome.runtime.getPackageDirectoryEntry( function(entry) { this.disk = entry }.bind(this) )
        WSC.BaseHandler.prototype.constructor.call(this)
    }
    var FavIconHandlerprototype = {
        get: function(path) {
            // USE HTML5 filesystem operations to read file
            
        },
        onReadFile: function(evt) {
            if (evt.error) {
                this.write('disk access error')
            } else {
                this.write(evt)
            }
        }
    }
    _.extend(StaticHandler.prototype,
             StaticHandlerprototype,
             WSC.BaseHandler.prototype
            )

Building

cd web-server-chrome
mkdir assets
cd makedeps
npm install
npm run make # this builds the app dependencies such as react and material-ui into a bundle
cd ../react-ui
npm run watch # Press ctrl-c if you just want to build it once.
# press ctrl-C if you are done editing
cd ../
bash package.sh

This creates package.zip, which can then be distributed.

Where to get it

Get it in the chrome web store: https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb

The default behavior right now is very simple. You choose a directory to serve static content. It is now able to stream large files and handle range requests. It also sets mime types correctly.

Here is an example project based on it: https://chrome.google.com/webstore/detail/flv-player/dhogabmliblgpadclikpkjfnnipeebjm


MIT license

I wrote this because the example app provided by google would lock and hang and had all sorts of nasty race conditions. Plus it would not stream large files or do range requests, HEAD requests, etc, etc.

The design of this is inspired heavily by to the Python Tornado Web library. In this as well as that, you create an "app" which registers handlers. Then under the hood it will accept connections, create an HTTPConnection object, and that has an associated IOStream object which handles the nonblocking read/write events for you.

See CREDITS file

Comments
  • Add PUT support for saving a file

    Add PUT support for saving a file

    I'm building an IDE for JavaScript. I want the user to be able to save their code in an ordinary ascii file in their choice of location in a file under the root of the server. Saving to the same location should replace the contents of the file previously at that location. The saved location should have an optional folder (or nested folder), a file name and a file extension like .js, .html, or .txt The capability to save non-ascii files like jpegs, audio, etc would be nice.

    enhancement 
    opened by cfry 25
  • Chrome max sockets reached when serving video

    Chrome max sockets reached when serving video

    First off, thanks for this library it's been a life saver for me. I'm embedding it in my chrome packaged app which allows you to setup a kiosk for any URL while providing an offline SDK that can be used to download images/video to the local machine which are then served through the local web server to the webview content (using html5 video element). I had attempted my own version a while ago and failed miserably until I came across this lib :).

    In one instance of a kiosk I am running a video loop where users can also click around and browse these videos. I am noticing that after some use (mostly when the user is clicking around) that the web server will stop serving the videos. When inspecting chrome://net-internals/#sockets I can see that the problem occurs when the active sockets for the web server reaches chrome's max limit of 6 per domain:

    image

    This seems to suggest that somehow sockets aren't being released even though my application should only be playing 2-3 videos at a time.

    I'm not sure if this is necessarily an issue with this library or my own code. I've tried to make sure that when a user selects a video to play, the old video element is removed but this did not seem to help. I also tried adding my own health check endpoint to the web server which gets pinged every 5s and will restart the web server if it times out - this also did not seem to release the sockets. The only thing that released the sockets was restarting the app.

    Has anyone run into this issue before or could potentially offer some advice on how to debug this further?

    opened by jschr 22
  • Is https possible?

    Is https possible?

    I think I might already know the answer to this but wanted to know if you had any ideas on how we could get ssl working. I'm not sure if chrome supports it.

    question 
    opened by kylepaulsen 18
  • Adds modrewrite functionality (SPA HTML5 location history)

    Adds modrewrite functionality (SPA HTML5 location history)

    Hi @kzahel

    I want this feature. To support $locationProvider.html5Mode(true);

    var modRewrite = require('connect-modrewrite');
    modRewrite(['^[^\\.]*$ /index.html [L]'])
    
    enhancement 
    opened by ajsb85 17
  • Link is not working

    Link is not working

    Hi, I am using the app on Google Chrome version 90.0.4430.93 I have tried to create a public link with a project on it. The link opens up the project on my computer well but when I try and share the link to others even after selecting "Accessible on local network" and "Also on internet" the link does not seem to open up on the other computer that is also running the same version of Google Chrome that I have. Any advice as to what I should do?

    opened by InfMedElo 15
  • Autostart

    Autostart

    Hi, great App, it does exactly what i need. Just one wish: it would be great, if i could define, that the app starts automaticly at browser-start. Dont know, if this is possible in Chrome.

    enhancement 
    opened by Linkstar75 14
  • Unhandled request. Did you select a folder to serve?

    Unhandled request. Did you select a folder to serve?

    I don't understand what's happening, I have an index.html with a form pointing at a processform.py script in the same folder. I have selected this folder for the server, but it gives me this error: Unhandled request. Did you select a folder to serve? Please, help. Thanks, Leo

    opened by lbaroncini 12
  • Blank window with old chrome versions

    Blank window with old chrome versions

    Hi, I'm using last version of this extension (01.16.2020) on Google Chrome ver.57 (cannot update it for some reason) and with this version preferences windows is totally blank. Thank you for this extension.

    unnamed

    opened by dariop 10
  • ERROR: polymer library not found. you need to use npm/bower in the polymer-ui folder.

    ERROR: polymer library not found. you need to use npm/bower in the polymer-ui folder.

    I'm on a Chromebook (HP Chromebook 13 G1) on the dev channel with the following version info:

    Google Chrome | 80.0.3987.18 (Official Build) dev (64-bit) -- | -- Revision | 1c1befe9f580a1613a5e6c301b967c29784bc603-refs/branch-heads/3987@{#239} Platform | 12739.12.0 (Official Build) dev-channel chell Firmware Version | Google_Chell.7820.315.2 ARC | 6078153 JavaScript | V8 8.0.426.9 Flash | 32.0.0.303 /opt/google/chrome/pepper/libpepflashplayer.so User Agent | Mozilla/5.0 (X11; CrOS x86_64 12739.12.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.18 Safari/537.36

    I've been using Web Server for Chrome for a couple of years, and I love it. After a recent restart of my computer for a browser update, the server suddenly stopped working. It hangs on startup with the message, "ERROR: polymer library not found. you need to use npm/bower in the polymer-ui folder." (Below the message appears an un-styled Welcome message and an un-styled Help section.)

    I've tried restarting the computer, disabling/re-enabling the app, and uninstalling/re-installing.

    Still I get the message. Any suggestions?

    bug priority 
    opened by dericgerlach 10
  • Add support for SPA using HTML5 history

    Add support for SPA using HTML5 history

    Hey, I think it's crucial nowadays to have support for SPA that are using modern html5 history for routing.

    In other words we need option to fallback on index.html in case actual folder/file is not found in directory.

    opened by flexchar 10
  • Add https functionality

    Add https functionality

    Add https:// This implements an option to use https and a way to simply create self signed certificate and private key. You can of course use a custem key-cert pair if you want.

    Many things today need https to be activated, including sensor suite for mobiles.

    refs: #113, #8

    My rationale for wanting this pull req, even though chrome apps discontinue: I would very much like this to be merged even though apps is not supported after 2022-06 I plan to use this webapp when I'am teaching. Students all have chromebooks and can't find much simpler way to serve https content. Like a webpage that responds to a mobile's accelerometer. At least we have a year before its closed down.

    Having https in the app in chromestore makes it much easier when students must work on there own at home (due to the pandemic)

    opened by mumme74 8
  • Alternative after December 2022

    Alternative after December 2022

    As we all probably know, Google has decided to kill off yet another useful thing. This time it's apps on Chrome.

    Sadly that means that us programmers and webdesigners will have to find a new way to test our work locally. Fear not! The awesome people @terreng and @ethanaobrien has come to save the day with their fork!

    https://github.com/terreng/simple-web-server https://simplewebserver.org/

    I am in NO way affiliated with them or their work, but I just stumbled over their work after looking for alternatives to use after 2022. Thank you @kzahel for your awesome Chrome App, it was great while it lasted.

    opened by ImLunaUwU 0
  • Choose folder button doesn't do anything

    Choose folder button doesn't do anything

    Hello, after adding Web server for Chrome to my extensions and opening it, I click on Choose folder to select my working folder but nothing happens. I tried to remove and add again the extension but nothing changes. I checked my security configuration and they seem to be ok. I'm using a Mac pc. Thanks for your help.

    opened by GiuseppeMacino 0
  • Vivaldi v4.0.2312.41 - [Choose Folder] button does not do anything

    Vivaldi v4.0.2312.41 - [Choose Folder] button does not do anything

    Vivaldi | 4.0.2312.41 (Stable channel) (64-bit) -- | -- Revision | 08924348d4b2ee3ae09abb1c9f1ce83300c32d12 OS | Windows 10 OS Version 2009 (Build 19043.1021) JavaScript | V8 9.1.269.39 User Agent | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.166 Safari/537.36 Command Line | "D:\Application\vivaldi.exe" --vivaldi-standalone --flag-switches-begin --disable-features=WebContentsForceDark --flag-switches-end --save-page-as-mhtml

    opened by Pashkuli 0
  • "Also on the internet" option just show a second local ip address

    The "also on the internet" option creates a second local address that cannot be used on computers outside the same network.

    This is what I get http://127.0.0.1:8887/ http://10.0.0.228:8887/

    Is there a way to fix this?

    opened by takiyao 0
  • Adding support for MHTML files

    Adding support for MHTML files

    Chromium-based browsers can save the complete webpage as a single Mime HTML file https://en.wikipedia.org/wiki/MHTML, but when opened locally, only HTML code is shown. Other resources like JS or CSS are blocked (Not allowed to load local resource). Per https://stackoverflow.com/questions/39007243/cannot-open-local-file-chrome-not-allowed-to-load-local-resource answer I was hoping this Chrome app will help, but my MHTML file is shown as a plain text.

    opened by jan-tosovsky-cz 0
HTTP server mocking and expectations library for Node.js

Nock HTTP server mocking and expectations library for Node.js Nock can be used to test modules that perform HTTP requests in isolation. For instance,

Nock 11.9k Jan 3, 2023
Async node.js implementation of the UDP Minecraft Server Query Protocol and TCP Minecraft Server List Ping Protocol

?? Mc Server Status Async node.js implementation of the UDP Minecraft Server Query Protocol and TCP Minecraft Server List Ping Protocol. Also availabl

Daniel 5 Nov 10, 2022
Promise based HTTP client for the browser and node.js

axios Promise based HTTP client for the browser and node.js New axios docs website: click here Table of Contents Features Browser Support Installing E

axios 98k Dec 31, 2022
🏊🏾 Simplified HTTP request client.

Deprecated! As of Feb 11th 2020, request is fully deprecated. No new changes are expected to land. In fact, none have landed for some time. For more i

request 25.6k Jan 4, 2023
Ajax for Node.js and browsers (JS HTTP client)

superagent Small progressive client-side HTTP request library, and Node.js module with the same API, supporting many high-level HTTP client features T

Sloth 16.2k Jan 1, 2023
A full-featured http proxy for node.js

node-http-proxy node-http-proxy is an HTTP programmable proxying library that supports websockets. It is suitable for implementing components such as

http ... PARTY! 13.1k Jan 3, 2023
🌐 Human-friendly and powerful HTTP request library for Node.js

Sindre's open source work is supported by the community. Special thanks to: Human-friendly and powerful HTTP request library for Node.js Moving from R

Sindre Sorhus 12.5k Jan 9, 2023
make streaming http requests

hyperquest treat http requests as a streaming transport The hyperquest api is a subset of request. This module works in the browser with browserify. r

James Halliday 711 Sep 8, 2022
HTTP Client Utilities

@hapi/wreck HTTP client utilities. wreck is part of the hapi ecosystem and was designed to work seamlessly with the hapi web framework and its other c

hapi.js 383 Nov 1, 2022
Full-featured, middleware-oriented, programmatic HTTP and WebSocket proxy for node.js

rocky A multipurpose, full-featured, middleware-oriented and hackable HTTP/S and WebSocket proxy with powerful built-in features such as versatile rou

Tom 370 Nov 24, 2022
Simplifies node HTTP request making.

Requestify - Simplifies node HTTP request making. Requestify is a super easy to use and extendable HTTP client for nodeJS + it supports cache (-:. Ins

Ran Mizrahi 222 Nov 28, 2022
Wrap native HTTP requests with RFC compliant cache support

cacheable-request Wrap native HTTP requests with RFC compliant cache support RFC 7234 compliant HTTP caching for native Node.js HTTP/HTTPS requests. C

Luke Childs 259 Dec 20, 2022
Run HTTP over UDP with Node.js

nodejs-httpp - Run HTTP over UDP based transport and Bring Web in Peer or P2P styles main js modules: udt.js, httpp.js, udts.js and httpps.js, that's

AppNet.Link 142 Aug 2, 2022
Global HTTP/HTTPS proxy agent configurable using environment variables.

global-agent Global HTTP/HTTPS proxy configurable using environment variables. Usage Setup proxy using global-agent/bootstrap Setup proxy using bootst

Gajus Kuizinas 267 Dec 20, 2022
HTTP Client for Visual Studio Code to POST JSON, XML, image, ... files to REST APIs

friflo POST Goal Main goal of this extension is storing all HTTP request & response data automatically as files in a VSCode workspace. This ensures th

Ullrich Praetz 2 Nov 18, 2021
Library agnostic in-process recording of http(s) requests and responses

@gr2m/http-recorder Library agnostic in-process recording of http(s) requests and responses Install npm install @gr2m/http-recorder Usage import http

Gregor Martynus 4 May 12, 2022
Very very very powerful, extensible http client for both node.js and browser.

ES-Fetch-API 中文 | English Very very very powerful, extensible http client for both node.js and browser. Why should you use ES-Fetch API? Still using a

null 17 Dec 12, 2022
Une petite extension google chrome qui permet de partager son code automatiquement sur Clash Of Code.

ClashOfCodeExtension Une petite extension google chrome qui permet de partager son code automatiquement sur Clash Of Code. Installation Télécharger le

Julien THILLARD 4 Apr 1, 2022
SPDY server on Node.js

SPDY Server for node.js With this module you can create HTTP2 / SPDY servers in node.js with natural http module interface and fallback to regular htt

SPDY & HTTP2 in JavaScript 2.8k Jan 4, 2023