Page MenuHomePhabricator

[Spike] Answer open questions on instrumentation for printing on desktop web
Closed, ResolvedPublic

Description

Background

T169730: Define and implement instrumentation for printing on desktop web needs some analysis prior to beginning work

Acceptance criteria

Answer the following open questions regarding the instrumentation in T169730: Define and implement instrumentation for printing on desktop web:

  • Where is this going to be implemented?
  • Does the schema capture everything that we need to answer the questions?
  • Which browsers can we do this reliably for? Can we target all of them with one or two approaches or can we only target one?

Event Timeline

Pulling this into the current sprint to ensure that T169730: Define and implement instrumentation for printing on desktop web is ready to be tackled next sprint.

Where is this going to be implemented?

Extension:WikimediaEvents seems a logical option as the kind of analysis we're trying to do is Wikimedia specific.


Does the schema capture everything that we need to answer the questions?

@Tbayer, do you think the schema and required data specified in the description of T169730 is sufficient for the data analysis purposes? @Tbayer has updated the parent task to capture all information we need.


Which browsers can we do this reliably for?

Here's the results for our Grade A browsers:

  • IE, Edge, and Firefox can use onbeforeprint and/or onafterprint events.
  • Chrome, Safari, and Opera 15+ can use matchmedia (see snippet below).
  • Opera 15 on Windows 8, for example, sends runs the matchmedia listener twice. We may want to throttle sending events for such cases.
  • Opera 12.14 doesn't seem to support either approach. (Tested on Windows 8, Opera 12.14)

Most of the grade B browsers can also utilise the approaches above, but some won't (for example Firefox version below 6 don't support onbeforeprint or onafterprint).

matchmedia snippet (source)

var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function(mql) {
    if (mql.matches) {
        console.log('onbeforeprint');
    };
});

Can we target all of them with one or two approaches or can we only target one?

Yes, I'd say check for the existence of onbeforeprint (no need for onafterprint according to T169730#3462071) and fall-back to matchmedia.

Where is this going to be implemented?

Extension:WikimediaEvents seems a logical option as the kind of analysis we're trying to do is Wikimedia specific.


Does the schema capture everything that we need to answer the questions?

@Tbayer, do you think the schema and required data specified in the description of T169730 is sufficient for the data analysis purposes?

I just made some more edits there; I think it's mostly ready now, but we should still sort out the various print events a bit more - see my question at T169730#3461493 .

@Tbayer thanks. I've clarified the difference between those events in a comment: T169730#3461548.

New question (hope this is clear enough...?):
If an asynchronous function call e.g. sendBeacon or:

setTimeout(function(){console.log('hello');}, 0)

is inside the event handler - are there any circumstances where it will not fire? e.g. if I abandon the print/close the window/never complete the print
I'm interested in whether the handler gets blocked as print is synchronous.

A quick test revealed that an event listener to onbeforeprint works as expected and runs its code when the event is triggered.

Thanks for checking @bmansurov !

I'm guessing this is ready for sign off since we said as much in standup.
Thanks @bmansurov for all the research and your thoroughness - it's definitely feeling more clear now than it was before!

phuedx claimed this task.

🎉

Thanks @bmansurov for all the research and your thoroughness - it's definitely feeling more clear now than it was before!

Seconded! Hopefully T169730: Define and implement instrumentation for printing on desktop web is clearer now.