Coder Social home page Coder Social logo

googlechrome / samples Goto Github PK

View Code? Open in Web Editor NEW
5.8K 356.0 2.4K 65.69 MB

A repo containing samples tied to new functionality in each release of Google Chrome.

Home Page: https://www.chromestatus.com/samples

License: Apache License 2.0

JavaScript 32.52% HTML 61.73% CSS 2.24% Ruby 0.01% C 0.09% Python 1.78% SCSS 0.06% Svelte 1.57%

samples's People

Contributors

addyosmani avatar bashi avatar beaufortfrancois avatar dandv avatar developit avatar devnook avatar ebidel avatar guest271314 avatar jeffposnick avatar joemarini avatar jonathangb avatar jpmedley avatar karolklp avatar loonybear avatar madmath avatar mathiasbynens avatar mfoltzgoogle avatar mustafa-x avatar paulirish avatar paulkinlan avatar paullewis avatar rsolomakhin avatar samdutton avatar samthor avatar scheib avatar surma avatar szager-chromium avatar tomayac avatar vasilvv avatar wibblymat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

samples's Issues

Externalize JS (and CSS?) files

Moving the discussion from #206

The benefits would be that it's generally a best practice, and it would make it easier to run ESLint and JSCS against the .js files directly, without having to extract them from the generated HTML. Now that we're on a Jekyll build for the site, we have a lot more flexibility.

The drawbacks would be that the View Source... experience is arguably worse for developers who want to learn about new features in context, since they'd have to match up what's going on with an external JavaScript file with the rest of the content on the main page.

The drawback might be mitigated by inlining the entire external .js file's source on the main page wrapped in a <div class="hightlight">, like we're currently doing for explicitly tagged snippets of the inline JavaScript source.

There's also the topic of whether we should do the same for CSS files. There are a handful of samples out there just demonstrate CSS functionality.

Sample for Web Application Manifest

This is a placeholder issue for us to write a sample for the Web App Manifest demonstrating usage. Mounir recently landed this. Although not yet in a public build, Chrome Android will use the Web Manifest for the "Add to homescreen" feature.

Spec: http://w3c.github.io/manifest/

Rough samples:

manifest.json

{
  "name": "2048 app",
  "icons": [{
        "src": "icon/lowres",
        "sizes": "64x64",
        "type": "image/webp"
      }, {
        "src": "icon/hd_small",
        "sizes": "64x64"
      }, {
        "src": "icon/hd_hi",
        "sizes": "128x128",
        "density": "2"
      }],
  "start_url": "/index.html",
  "display": "fullscreen",
  "orientation": "landscape"
}

index.html

<!doctype>
<html>
<title>My app</title>

<!-- Startup configuration -->
<link rel="manifest" href="manifest.json">

Intent to Ship:
https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/EbAMnvBUU80

Commits:

https://chromium.googlesource.com/chromium/src/+/b225ae560fea0648b61fad36b5972221a7f5c47d
https://chromium.googlesource.com/chromium/src/+/f60720832599bc7306d9e37e3cef5ceee4c224ce
https://chromium.googlesource.com/chromium/src/+/96297a73c48ff299e45eac62b967a8e333569602
https://chromium.googlesource.com/chromium/src/+/9317a291b84457b9a8feb8ecd94d0593bb0fff9b

SW Sample: Returning Mock Data

It should demonstrate basic registration, and then an onfetch handler that returns hardcoded data in response to requests that match specific criteria.

An example would be intercepting all requests for a specific API call and instead of fetch()ing them, returning a hardcoded JSON document.

(This would be useful within the context of unit testing code that relies on API responses.)

SW Sample: Using PostMessage

It should demonstrate basic registration, and then have the client page send specific requests to the SW script via postMessage() on the client page/the onmessage handler in the SW script.

For the purposes of this example they could be simple strings that are echoed back, but in the real world a useful case would be to send a request from the client page to the SW to cache a URL or to update some sort of SW configuration.

SW: Ensure consistent capitalization

Reminder to scrub all the samples to use consistent capitalization—they're "service worker(s)", not "Service Worker(s)" or "ServiceWorker(s)".

SW Sample: Caching of Selective Resources

It should demonstrate basic registration, and then an onfetch handler that selectively caches responses based on multiple criteria:

  • Request URL pattern (e.g. only cache URLs hosted on example.com)
  • Response MIME type (e.g. only cache image/* resposnes). Subsequent requests for the same URL are served from the cache.
  • Any other ideas?

Until the native Caches API is available, it should use https://github.com/coonsta/cache-polyfill

Object.assign sample

Object.assign() now makes it easy for developers to clone or merge objects by copying all the values of enumerable properties from one or more source objects to a target object.

media-hover-pointer sample

in the demo https://googlechrome.github.io/samples/media-hover-pointer/ it reads

if a user is on a tablet with a connected a mouse, 'any-pointer' will be satisfied. If the mouse is then removed, the browser will report 'any-pointer' as none.

Maybe I'm misunderstanding the spec, but why would/should any-pointer be none once the mouse is removed? wouldn't the fact that the touchscreen interface is still present count as a pointer device?

Templatize as much as possible

There's an enormous amount of boilerplate HTML (and some JS + CSS) that used in every sample. I'm guilty of encouraging a copy/paste model that got us to this point.

Moving to a model in which we took advantage of GitHub's Jekyll support and abstracted away most of the boilerplate into a shared template would make a lot of sense. Samples that needed to do something that didn't fit into the template would still have the flexibility to commit a full set of HTML + JS + CSS.

I think it would also be possible to automate generating an index page as part of this process, closing #37

SW Sample: Service Worker URL Parameters

It should demonstrating registration in which data from the client page is encoded as a URL parameter appended to the SW script URL. The SW then deserializes that URL parameter data and makes use of it.

An example would be a client page that passes in a list of URLs that should be prefetched, as an alternative to a hardcoded a list of prefetch URLs within the SW's oninstall handler.

SW Sample: Returning Fallback Data

It should demonstrate basic registration, and then an onfetch handler that returns default data when the fetch() request fails.

A potential example would be to fetch() an API call that will always fail (such as a YouTube Data API v3 request that omits an API key and returns a HTTP 403) and return a fallback JSON document in its place.

Use eslint to standardize on JS code style

It's been suggested in the past (by @gauntface I believe) to include a top-level jscs configuration in this repo. It might be difficult to automatically enforce the styles, but including a reference that folks could opt into would do some good.

SW Sample: Registration with Immediate Replacement

It should demonstrate standard registration with a technique for immediately elevating the installing SW to be the controlling SW. (I think this would entail forcing the page to refresh, but it would be good to confirm the best practice first.)

App Install Banner issue

I've launched the app install banner sample pages on Chrome for Android 44.0.2 (tried the latest Dev + Beta builds from the Play store). After enabling chrome://flags/#bypass-app-banner-engagement-checks and relaunching Chrome, I still don't see any banner.

Any ideas? Note: I'm not signed into Chrome, is this a requirement?

/cc @PaulKinlan

SW Sample: storing data

I have a session token in my page that I want to use in my SW.

I'm using postMessage to send it to the SW and then plan on using IDB to store it there.

A small sample that stores bits of (non-response) data persistently would be pretty nice, imho.

Ideas for Push API recipes

  • Registration (Google Cloud Console, manifest file, need to register from document first, sending data to their server)
  • Sending a simple message (Perhaps a very simple back-end example for sending something to GCM, similar to what Matt is using)
  • Receiving a message (The "onpush" event, why no payload, using fetch())
  • Displaying a notification (Why? Good practices for engaging users (icon + title + body), store data in IDB, maybe "tag" hack?)
  • Handling a notificationclick even (focusing or opening windows)

These are following a sync with Peter a week or so ago. We've since opted to ship a single larger sample in #79, but these could still be useful to explore when time allows.

Update App Banner examples

Need to include:

  • Cancelable example
  • User response example (did they install or not)
  • Shuffle the examples around to make it easier to navigate.

Bug: push-messaging-and-notifications doesn't work on hard reload

In file samples/push-messaging-and-notifications/main.js
Line 174: navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) {

Problem:

serviceWorker is never ready if you do a "hard reload" (shift-reload icon) or "empty cache and hard reload"
Chrome version 44.0.2403.39 beta-m (64-bit)

Test: try it at https://widgetsign.com/chrome_samples/push-messaging-and-notifications/
Fault: the button is never enabled if you do a shift-reload.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.