-
Notifications
You must be signed in to change notification settings - Fork 14
Development
Resources on the various web and Chrome extension APIs used
IndexedDB
FileSystem API
Chrome Extensions
- Messaging: https://developer.chrome.com/extensions/messaging
- How to detect when an extension has been updated or installed - stack overflow
- When an unpacked extension is reloaded, the
previousVersion
property of the details will be the same aschrome.runtime.getManifest().version
- When an unpacked extension is reloaded, the
JSON Validation
- JSON Schema
- is-my-json-valid
Testing Chrome Extensions
- How to test Chrome Extensions: http://stackoverflow.com/questions/2869827/how-to-test-chrome-extensions
- Testing Chrome Extensions with Jasmine: http://blog.robertosoares.me/blog/2012/08/08/testing-chrome-extensions-with-jasmine/
- Testing Browser Extensions: http://stackoverflow.com/questions/14798528/testing-browser-extensions/17370531#17370531
- Example Extension that uses testing and good organization: https://github.com/buunguyen/octotree
Javascript
- JavaScript Optimization: https://developers.google.com/speed/articles/optimizing-javascript
Chrome Debugging - for issues that go beyond exceptions (e.g. crashes)
- Enable logging in Chrome: http://www.chromium.org/for-testers/enable-logging
- Enabling Chrome crash dumps: http://superuser.com/questions/624/where-is-google-chrome-crash-dump-located
- How to get crash information when no log is generated: http://stackoverflow.com/questions/8764253/google-chrome-crashes-without-any-log
- Debug an extension that is crashing - stack overflow
-
tail -f
capability in Windows/Sublime Text - stack overflow- Just use something like baretail, which works just fine.
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 toweb_accessible_resources
in manifest Specific Answers - answers to questions we've had along the way
- use
- 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 isjson
.
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 calleddefinitions.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.
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