This repository has been archived by the owner on Dec 30, 2024. It is now read-only.
Replies: 3 comments 1 reply
-
I've forked the repo and written a basic approach. It should suffice for our next batch of evaluations starting in March. Any thoughts? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hey! |
Beta Was this translation helpful? Give feedback.
1 reply
-
I've created #22 and qualweb/types#6 to work on the changes. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey guys!
We've talked about the possibility of extending QualWeb's interface in a way that would allow plugins (like CMP "cookie banner" handling, or login automation) to augment QualWeb in useful ways. The post is a bit long, so I hope you'll bear with me - I wanted to make sure I got the important details written down :)
Use cases
Two notable use cases were mentioned initially:
Requirements
From those use cases, we've identified these initial requirements for QualWeb to support them:
Page
object in order to run its code.Page
are asynchronous, which means that QualWeb must be able to delay its evaluation until a plugin has finished processing.Possible interfaces
During our online discussion, we noted event emitters, callback parameters, and express-style middleware as inspirations for a design.
Event emitter and Express
Event emitters allow listeners to hook into specific events, typically with a generic 'on' method. You'd use it like
qualweb.on('beforePageLoad', myCallback)
orqualweb.on('afterPageLoad', anotherCallback)
. The benefit of event emitters is that the interface is quite simple, and the heavy lifting can be delegated to Node'sEventEmitter
class. When a specific event needs to be raised, you simply callEventEmitter#emit()
with the event name and payload. However, I'm not 100% sure thatEventEmitter
waits for asynchronous functions by default, which is a hard requirement for most use cases that work with the puppeteer API.Express-stye middleware looks a lot like event emitters, but without being able to specify the specific events you'd want to listen for,
express#use(middlewarePlugin)
. This is fine for express, since the only "event" that passes through express is HTTP(S) requests, and middleware functions like transformations in a chain before a response is (possibly) sent back to the request source.Passing a callback
Passing callback parameters to
QualWeb#evaluate()
would mean expandingQualwebOptions
with new fields for specifying lifecycle callbacks:Plugins for QualWeb
Initially, I had been thinking of suggesting an interface in the style of EventEmitter (
QualWeb#on('beforePageLoad', ...)
) because it would allow multiple different listeners and directly specify the event you wanted to hook onto.After our talk (and the express-style "use" was mentioned), it struck me that a single plugin might want/need to hook into multiple events at different times. As an example, a CMP "banner" plugin might want to listen on "afterPageLoad" to detect and handle banners, but then store the resulting cookies and re-use them in subsequent URLs in a "beforePageLoad" call. While you could do that in a plugin by calling a "on" method twice (with different parameters), it might be more elegant if you pass a full plugin object/constructor instead. Example:
I think that's enough of a wall of text, to being with. I'll leave it at this as the first post :)
Beta Was this translation helpful? Give feedback.
All reactions