Skip to content
Christopher Hunt edited this page Dec 30, 2015 · 4 revisions

Resources

Resources on the various web and Chrome extension APIs used

IndexedDB

FileSystem API

Chrome Extensions

JSON Validation

Testing Chrome Extensions

Javascript

Chrome Debugging - for issues that go beyond exceptions (e.g. crashes)

Specific Questions - for items that don't fall under general categories

  • How to compare version numbers in JS - stack overflow
  • How to get image data given an image that has been loaded on the page - stack overflow
    • Just put it on a canvas and then use getDataURL
  • Handling very large objects in JavaScript - stack overflow
  • What's the limit on the length of a key in JavaScript? - stack overflow
    • The spec doesn't define anything, but in most modern browsers you're good up to 2^28 chars, i.e. 500mb
  • What's the limit on the length of a string in JavaScript? - stack overflow
    • The spec doesn't say much, but in most modern browsers you're good up to 2^28 chars, i.e. 500mb
  • How to reference extension resources from CSS? - stack overflow
    • use url('chrome-extension://__MSG_@@extension_id__/path/to/resource.png') and make sure to add to web_accessible_resources in manifest Specific Answers - answers to questions we've had along the way
  • Do elements (such as images) need to be added to the document in order to be used for canvas drawing? No.
  • Can blobs be stored in chrome.storage? No, an object is returned, but without the data.
  • Changes to chrome.storage aren't propagated out to listeners running on different content scripts.
  • How can you load JSON in NodeJS? Either as a file or using require directly if the file extension is json.

JSON Schema

Main website

JSON Schema Creator

JSON Schema visualizer

JSON Schema book (great!)

JSON Schema allows definition of the structure of JSON. It is to JSON what XSD is to XML.

Validating against a schema is just one part of validating data. It is the structural level of the information and only needs to adhere to that. The actual content apart from the types needs to be validated in another pass as the semantic ("meaningful") level.

{} <- valid json schema type keyword keyword is just a key of a key-value pair for a json schema object or nested object.

JSON schema is differentiated from JSON by the inclusion of a $schema keyword which references the associated version.

Some other keywords:

  • (metadata)
  • title
  • description
  • default

enum - array of values. if type keyword is present in same enclosing body then the that takes precedence, you can have an enum with multiple types.

schemas can be combined in multiple ways so values have to satisfy some criteria on a set such as

  • allOf
  • anyOf
  • oneOf

where each are an array of schemas.

not is just an object that something should not match to.

complex documents

  • of course we want to reuse consistent parts of a schema.

JSON pointer syntax is like xpath for JSON.

  • # refers to the current JSON document/object
  • / goes into a property, similar to using '.' to access the properties of an object in JS.
  • #/definitions/address - references the property "address" of the property "definitions" of the current document.
  • definitions.json#/address would get the address definition from the file called definitions.json which could be interpreted as being in the same location as the current document.

The $ref keyword allows referencing other parts of a document which are then replaced with the thing pointed to.

Generally if there is more than one place that something needs to be used, then it is put in a definitions key under the parent schema and referenced using $ref

$ref can be used with combining keywords to create powerful behaviors.

extending a referenced schema can be done with allOf, referencing the schema, and then adding other schemas in the allOf array that should be matched to.

required is a keyword which is an array of strings matching the stated properties.

array additionalItems? additionalItems is not needed when items keyword is set to a single schema, and should be omitted arrays can do "list" validations or "tuple" validations. the former is where all the items are the same and the latter is where the indices correspond to specific values.

"null" is the type for values that may be null.

program that takes schemas and runs validations on them: https://github.com/mafintosh/is-my-json-valid

One part of JSON schema that isn't implemented in most JSON-schema-based validators is resolving of external references. Some, like is-my-json-valid, allow you to define schemas to be used when referenced in the schema you pass to the validator constructor. In that case, you just need to iterate and pre-load your referenced schemas.

File System API

How to view FileSystem contents in Chrome apps - stack overflow

FileSystem has a name and root, root is a DirectoryEntry, which is a directory-like interface to interact with contained files.

DirectoryReader has method readEntries which takes a success and error callback. It should be called repeatedly until an empty array is returned, indicating that the end of the list has been reached. the array passed to the success callback has entries.

FileSystem Errors and Exceptions - w3.org

Clone this wiki locally