System override API in bootstrap.js?

28 views
Skip to first unread message

Michael Risch

unread,
Feb 23, 2026, 1:12:29 AM (4 days ago) Feb 23
to zotero-dev
Hi -

I would like to work on a plugin that preprocesses citations before they are passed to the csl file. Let's say I want a slimmed down version of juris-m, and want to inject my own abbreviations in if journal abbrev is empty, or that I want to read the juris-m "extra" jurisdiction and/or reporter fields and use its bluebooking. This is more out of personal curiosity and experiment, but also recognition that Frank can't do this forever, isn't getting a lot of help, and this is pretty important to a lot of people who need real bluebooking.

Two AI systems seem to think I can register a function to retrieve an item that will trigger when the citeprocengine gets called, but it just doesn't work, and then they suddenly say, oh no, Zotero 7/8 does something different (which I think is completely hallucinated). I would just look at a doc to see, but I can't find one that covers overriding/notification triggers, and none of the plugins out there seem to be clear examples in the area of citeprocengine, at least (betterbibtex probably was but it doesn't work anymore, so maybe that's a sign).

Anyway, any pointers to docs or examples would be helpful. Or noting that this is a fool's errand would be helpful. Thanks!

XY Wong

unread,
Feb 23, 2026, 9:02:53 AM (4 days ago) Feb 23
to zotero-dev
Some plugins do have various modifications on the "System" APIs (monkey-patching). According to your description, 

> preprocesses citations before they are passed to the csl file

Probably, you will be able to find the specific function that gets called there and patch it so that you can do whatever you want to do.

As for the AI suggestions on behaviors on 7/8, most of the major version changes are marked in the docs (please see other posts in the dev list about major version changes), if not noted, what AI says is likely not true.

Michael Risch

unread,
Feb 23, 2026, 9:52:50 AM (4 days ago) Feb 23
to zoter...@googlegroups.com
Yeah, this isn't listed on those pages - I looked there first. But I also didn't see any other doc on an API for monkey patching, which is why I wrote the post. I dug a bit into the Zotero source code last night but finding stuff was difficult.

The AI suggests something like this inside startup()
patchCiteProc()
if (!Zotero.CiteProc || !Zotero.CiteProc.System) return
const self = this

// --- PATCH 1: Inject Custom Fields --- this.originalRetrieveItem = Zotero.CiteProc.System.prototype.retrieveItem; 

Zotero.CiteProc.System.prototype.retrieveItem = function (id) { let itemData = self.originalRetrieveItem.apply(this, arguments); 

And then later something like this to intercept abbreviations
this.originalGetAbbreviation = Zotero.CiteProc.System.prototype.getAbbreviation; Zotero.CiteProc.System.prototype.getAbbreviation = function (styleID, abbrevs, name, category, itemData)

And later this to intercept the style creation to load different case styles
this.originalRetrieveStyleModule = Zotero.CiteProc.System.prototype.retrieveStyleModule; Zotero.CiteProc.System.prototype.retrieveStyleModule = function (jurisdiction, preference)

As far as I can tell through debug logs, none of these get fired, ever. I didn't think to get rid of 
if (!Zotero.CiteProc || !Zotero.CiteProc.System) return - maybe that's the issue. But any other input on if this monkey patching is even feasible, I would appreciate it.


--
You received this message because you are subscribed to a topic in the Google Groups "zotero-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/zotero-dev/gHv5cu4fUbY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to zotero-dev+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/zotero-dev/3cf153fc-b16a-47c2-a32c-7891a516667bn%40googlegroups.com.

Michael Risch

unread,
Feb 23, 2026, 12:11:13 PM (4 days ago) Feb 23
to zoter...@googlegroups.com
I am making headway. It appears that some of the Zotero objects being called were not the right ones. The patch appears to take hold, at least, once I fixed that, though other ones remain elusive.

Emiliano Heyns

unread,
Feb 23, 2026, 12:20:25 PM (4 days ago) Feb 23
to zotero-dev
Please don't use AI for monkey patches. Monkey patches are potentially very disruptive and can be actually damaging, as in data loss, or in the case of the citation processor, mess with peoples papers. You need to understand the code you are monkey patching and the edge cases you are introducing very well. AI is not going to do that. If you want something targeted, I might be able to help

Here is a general framework for patching and unpatching code (you must unpatch on uninstall/disable or you are going to leave stuff broken)

https://github.com/retorquere/zotero-better-bibtex/blob/master/content/monkey-patch.ts

here is how you use it

https://github.com/retorquere/zotero-better-bibtex/blob/master/content/better-bibtex.ts#L206

and unpatch in uninstall/disable

monkey.disableAll()

Michael Risch

unread,
Feb 23, 2026, 8:45:42 PM (4 days ago) Feb 23
to zoter...@googlegroups.com
Yeah, so it's a starting point, and not a bad one given the lack of docs. But I'm definitely finding I have to eat my Wheaties here. As I teach my own students, I would never release something that I didn't understand how it worked and verify was correct.

Reply all
Reply to author
Forward
0 new messages