help-librejs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-librejs] LibreJS as a standalone library (and program)


From: Fabio Pesari
Subject: [Help-librejs] LibreJS as a standalone library (and program)
Date: Thu, 07 May 2015 00:33:11 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.6.0

LibreJS is great, but right now it only works on Mozilla Firefox (and
derivatives) and checking pages for compliance is a cumbersome process
that cannot be easily automated. The best option right now is using
Mozilla's Marionette technology, which is still experimental and has a
single implementation (written in Python 2.x, unfortunately).

But why is it so? LibreJS should require an entire web browser. I think
that the LibreJS codebase should be more abstract (instead of relying
directly on the Mozilla Addon SDK) and use third-party libraries written
in JavaScript to allow LibreJS to exist as a standalone library, so that
programs can be built upon it.

This would make porting LibreJS to other browsers trivial, and would
allow any other JavaScript-based environment (such as Node.JS or
Nashorn) to use LibreJS. It would also enable people to put "Validate
with LibreJS" buttons in webpages, which would spread awareness.

As a library, at the very least, LibreJS should implement a function
like this:

LibreJS.check_html(data)

which would return this JSON data:

{
  // "10" is the line number of the nonfree code
  "10": {
             "content": "...", // or null
             "source":  "...", // or null
             "reason":  "...",
             ...                     // other metadata
           },
  ...
}

As a command line program, LibreJS should be able to generate both the
JSON data described above (with a --json flag) and human-readable output
(and maybe other formats, like CSV), such as:

$ librejs libre-page.html

> (no output)

$ librejs bad-page.html

> bad-page.html: nonfree code detected
> 10: innerHTML identifier (...item.innerHTML = 'blah';...)
> 25: external script (http://...)

Maybe you can pass it the name of an HTML file containing the web labels:

$ librejs bad-page.html --labels labels.html

or maybe you can make it output the "good" matches, too:

$ librejs bad-page.html --verbose
> 2: [Libre] (function clean() { a = 5; ... })
> 10: [Nonfree] ...

Such a program could be written using Node.JS' file I/O and command line
parsing libraries, since it appears to be the most popular JavaScript
standalone environment (not a big fan but this might be one of its few
legit use cases).

Now, which libraries could make this easier? I think the Esprima library
should be considered for parsing JavaScript, and the DOMParser from the
standard Web API should suffice for parsing HTML.

That doesn't mean that LibreJS should ditch the Mozilla components
altogether - they are a lot faster than JavaScript libraries, after all.
But using more abstractions (such as dependency injection and the
adapter pattern) in LibreJS' codebase would allow to pick the right
implementation according to the environment.

Of course, such a library could be implemented in any language, but I'm
suggesting we use JavaScript because it would allow to reuse the same code.

Any thoughts or opinions?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]