Skip to main content

Developing Userscripts for Chrome (caveats)

To develop Chrome extensions, crx is the best way. But the user scripts that are developed in general for Greasemonkey can also be delivered for Chrome, if a few easy rules are followed.

1. @required and @resource don't work.

By default, atleast for now, These two Userscript metatags donot work on Chrome. If you need to load a js file, instead of using @required - try to use document.createElement. Similarly with @resource.

2. Some GreaseMonkey helper methods don't work or are restricted.

Methods with GM_ prefix from userscript api may not work. Particularly, unsafeWindow, GM_registerMenuCommand, GM_setValue, or GM_getValue are not supported. GM_xmlhttpRequest will work but not only on the same domain.

3. @includes are not shown while installing.
This may not be a deal breaker for developers, but sure is for users. The patterns used in @include is not shown while installing. Instead a generic message is shown as below. This message may scare the users away.


To over come this, add @match and show the @include pattern there. The message window pics up the domain portion of the pattern.


This actually can be used maliciously. A developer may install a script with a different include pattern and show a different match pattern, there by luring the users to install a malicious script. Although Chrome follows the @include pattern to add script to the page. Just the installation window pops open with @match pattern. Please use this for responsibly.

Here is comments from The Chromium source that explains the reasoning, valid/invalid patterns @match can take:
// Examples of valid patterns:
// - http://*/*
// - http://*/foo*
// - https://**bar
// - file://monkey*
// -*
// Examples of invalid patterns:
// - http://* -- path not specified
// - http://*foo/bar -- * not allowed as substring of host component
// - http://foo.*.bar/baz -- * must be first component
// - http:/bar -- scheme separator not found
// - foo://* -- invalid scheme
// - chrome:// -- we don't support chrome internal URLs
// Design rationale:
// * We need to be able to tell users what 'sites' a given URLPattern will
//   affect. For example "This extension will interact with the site
//   ''.
// * We'd like to be able to convert as many existing Greasemonkey @include
//   patterns to URLPatterns as possible. Greasemonkey @include patterns are
//   simple globs, so this won't be perfect.
// * Although we would like to support any scheme, it isn't clear what to tell
//   users about URLPatterns that affect data or javascript URLs, so those are
//   left out for now.

Popular posts from this blog

Javascript: Convert Strings to Binary (and representing in a nerdy way!)

I follow those GoogleDevelopers Videos. Sometime back, in one of the presentations on GoogleIO, there was this interesting string of dots at the bottom of each page of the presentation. They looked like random big and small dots. A similar bunch of dots were also on the T-shirt of a presenter was wearing in another presentation. While it seemed something in the pattern, I could not find what it was. Finally, another presenter cleared the matter that those dots are just binary representation of "GOOGLEIO" (So much for advertizing Google IO, Impressive!).

So I wanna do it. Takes me back to days of those DSP classes at school. Nerdy me had to churn some old brain cells. I remember those first programming language classes in Pascal and C when you were asked to do fibonacci series and converting a binary string to ascii codes. That *experience* came handy here: Check it out!

Text to Binarize:
For those who came to copy the javascript code to convert string to binary, Here it is…

Add jquery in Chrome console

Many a time, a page you are debugging doesnot have jquery. This simple js will add(or prompt you to overwrite) jquery to any page from chrome console.


MySql Copying Table Structures.

Some times you need to copy only table structures across databases. This article describes two ways of doing it.

If the whole database schema need to be exported, mysqldump is very effective. A --nodata flag will dump all tables' schema.

Like this.
mysqldump --nodata -p -u username databaseName
But if you want to copy a specific table, individually, you could use "create table like" feature. You could create it even from a different database. However it must be on the same mysqld instance.

Like this.
create table newtable like oldtable; --Or from a table in other database create table mytable like otherdatabase.tablename;