Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
dev:client_coding:javascript_api [2018/09/16 13:23] – [Managing citations and bibliographies] fix and expand related items zuphilipdev:client_coding:javascript_api [2019/01/22 00:42] – [An Easy Debugging Environment] dstillman
Line 7: Line 7:
 ====== Zotero JavaScript API ====== ====== Zotero JavaScript API ======
  
-Whereas Zotero's [[dev:web_api|Server API]] allows read and write access to online Zotero libraries, it is also possible to access the local Zotero client through the JavaScript API. (It is also possible to [[dev/client_coding/direct_sqlite_database_access|directly access the local SQLite database]], but that approach is much more fragile.)+Whereas Zotero's [[dev:web_api|Web API]] allows read and write access to online Zotero libraries, it is also possible to access the local Zotero client through the local JavaScript API. (It is also possible to [[dev/client_coding/direct_sqlite_database_access|directly access the local SQLite database]], but that approach is much more fragile.)
  
 Note that the (mostly user-contributed) documentation of the JavaScript API is not comprehensive. If you use the JavaScript API in ways beyond what's described here, please consider expanding this wiki page. Note that the (mostly user-contributed) documentation of the JavaScript API is not comprehensive. If you use the JavaScript API in ways beyond what's described here, please consider expanding this wiki page.
Line 22: Line 22:
     * [[http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference|MDC Core JavaScript 1.5 Reference]] (also note [[http://developer.mozilla.org/en/docs/New_in_JavaScript_1.6|New in JavaScript 1.6]] and [[http://developer.mozilla.org/en/docs/New_in_JavaScript_1.7|New in JavaScript 1.7]])     * [[http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference|MDC Core JavaScript 1.5 Reference]] (also note [[http://developer.mozilla.org/en/docs/New_in_JavaScript_1.6|New in JavaScript 1.6]] and [[http://developer.mozilla.org/en/docs/New_in_JavaScript_1.7|New in JavaScript 1.7]])
  
-===== An Easy Debugging Environment =====+===== Running Ad Hoc JavaScript in Zotero =====
  
-Various Firefox extensions create servers within Firefox that expose the internal Firefox environment, including Zotero internalsThese can be used as shells for easy experimentationThese include+Zotero 5.0.61 and later include an option to run arbitrary privileged JavaScript:
- +
-  * [[https://addons.mozilla.org/en-US/firefox/addon/execute-js/|ExecuteJS]] +
-  * [[http://davidkellogg.com/wiki/Main_Page|Plain Old Webserver]] (POW) - [[http://github.com/singingfish/zotero-browser|Zotero Browser]] is an example of getting POW to interact with Zotero to create rich annotated bibliographies. +
-  * [[http://wiki.github.com/bard/mozrepl/|MozRepl]] - interactive shell, available by telnetting to localhost on port 4242 (by default). Linux and Mac OS X users can use the built in telnet client. Windows users should use [[http://www.chiark.greenend.org.uk/~sgtatham/putty/|Putty]]. There is also a Firefox plugin to provide MozRepl access [[http://ubik.cc/2009/09/mozrepl-in-a-panel.html|directly inside Firefox]]. +
-    * **Potential MozRepl Problems**: Longer scripts can time out non-deterministically. A solution to this is to either send the code to the terminal application in smaller sized chunks, or to keep pasting the code in until it works.  Use an external library (like CPAN's MozRepl module) for finer grained control.   Syntax errors can cause silent failure. Avoid this by avoiding excessively long blocks of procedural code - factor everything into smaller functions wherever possible. +
- +
-Perl programmers should be aware of the [[http://search.cpan.org/perldoc?MozRepl|MozRepl]] CPAN module, and the closely related [[http://search.cpan.org/perldoc?MozRepl::RemoteObject|MozRepl::RemoteObject]] which allows you to access JavaScript objects from inside Perl programs.+
  
 +  - In the Advanced pane of the Zotero preferences, select Config Editor, and then set ''devtools.chrome.enabled'' to ''true'' and restart Zotero.
 +  - In the Tools menu, select Run JavaScript. Open the Error Console, which also appears in Tools, will also be helpful.
 +  - In the window that opens, enter JavaScript in the Code textbox and click Run or press Cmd-R/Ctrl-R. The return value of the last line will appear in the textbox on the right.
  
 +(Before Zotero 5.0.61 is released, you'll need to install the [[:dev_builds|Zotero beta]] to use this feature.)
 ===== The Zotero Object ==== ===== The Zotero Object ====
  
dev/client_coding/javascript_api.txt · Last modified: 2022/07/02 18:22 by dstillman