Skip to content

Add an option to include a screenshot of the problem in feedback emails. - #3247

Open
Alex-Jordan wants to merge 10 commits into
openwebwork:developfrom
Alex-Jordan:screenshot
Open

Alex-Jordan wants to merge 10 commits into
openwebwork:developfrom
Alex-Jordan:screenshot

Conversation

@Alex-Jordan

Copy link
Copy Markdown
Contributor

As described in the title. But also, if the problem fails to render, rather than a screenshot, include the error message in the email. When I have $external_auth set, this will be useful for letting me see the student's issue without needing to log in. (Maybe this feature should only come into play when $external_auth is set?)

Claude's first commit message explains more fully how the screenshot behavior is controlled:

If $mail{feedbackScreenshot} is set in site.conf (it is disabled by
default), then when the "Email Instructor" button is clicked on a problem
page, a screenshot of the rendered problem is taken in the browser and sent to
the feedback page. The feedback page shows the screenshot with a checkbox that
allows the student to choose to include it. The checkbox is unchecked by
default, so that screenshots are only sent when they would be helpful. The
screenshot is embedded in the html version of the email (in a
multipart/related part referenced by its content id), and attached to the text
version of the email (in a multipart/mixed part). Screenshots larger than the
maximum attachment size are not included.

The screenshot is taken with the modern-screenshot javascript package. The
following issues with that package are worked around:

  • Pseudo elements whose content is an image (such as the icons in the answer
    feedback buttons) are rendered as the text of the image url.
  • Open popovers (such as answer feedback popovers) are positioned relative to
    their offset parent, which is often outside of the problem body, and so are
    not in the right place or not in the screenshot at all. The screenshot is
    also expanded to include popovers that extend outside of the problem body.
  • An overflow of visible is not copied for svg elements, and so parts of
    MathJax output that extend outside of the svg (for example the tail of a Q)
    are clipped.

The PNG images created by browsers are not well compressed. So the screenshot
is converted to a palette image with at most 256 colors and compressed with
GD when it is received by the server. This reduces the size of a typical
screenshot to about 30% of the original size with no visible difference.

@drgrice1

Copy link
Copy Markdown
Member

I mentioned the other day that a PGchoicemacros.pl problem was not working well with this, and that a parserCheckboxList.pl problem did not have those issues. However, it turns out it had nothing to do with which macro was used. It was just that the problem that didn't work had feedback shown because it had been answered, but the other problem was not answered. Here are screenshots from the parserCheckboxList.pl macro that show the issue.

This is an actual screenshot of the problem answered in the set:
actual-screenshot

This is the resulting JavaScript screenshot:
screenshot-screenshot

The actual check boxes are not shown.

@Alex-Jordan

Copy link
Copy Markdown
Contributor Author

Sounds like another issue with the modern-screenshot package. I could ask Claude to investigate and it might propose another adjustment to compensate. But before I do that, how are we feeling about this feature? I don't need to insist on adding this.

An aside. I did notice something sort of like this, but not with a homework system. Sometimes when people share links to Google Docs, Google Sheets, etc., the email will have an image of that document. But it is static from that moment, and if the underlying document is updated, the recipient of the email still sees a snapshot from when the email was sent.

@Alex-Jordan

Copy link
Copy Markdown
Contributor Author

With Claude's help, this now draws spans for checkboxes and radio buttons in the copy of the div that is used by modern-screenshot to take the screenshot. In my testing, I now see checked/selected boxes/buttons as appropriate.

@pstaabp

pstaabp commented Nov 3, 2026

Copy link
Copy Markdown
Member

Trying to test this. I don't have a smtp set up on my develop machine. It doesn't look like the screenshot is saved in a tmp directory anywhere or am I wrong. If this is true, is there another way to view the screenshot?

@Alex-Jordan

Alex-Jordan commented Nov 3, 2026 via email •

Copy link
Copy Markdown
Contributor Author

@pstaabp

pstaabp commented Nov 10, 2026

Copy link
Copy Markdown
Member

Finally tracked down the reason I never saw the screenshot. I think this might be a safari issue. @Alex-Jordan did you test in Safari?

I'm getting a javascript error: Blocked script execution in 'about:srcdoc' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.

I'm seeing everything correctly in chrome.

I'll look into seeing if this is on my end (some setting) or there's an option in modern-screenshot

@Alex-Jordan

Copy link
Copy Markdown
Contributor Author

This is now rebased, addressing some conflicts.

I checked with Safari and did not experience what @pstaabp experienced. However, there was an issue with box shadow borders being offset in the screenshot. Claude pinned this down as coming from WebKit browsers drawing box shadows differently, and added a commit to address that by drawing such things differently for modern-screenshot to take its screenshot.

@pstaabp Is there some extension you have in Safari that might be responsible for the blocking you experienced?

@pstaabp

pstaabp commented Nov 17, 2026

Copy link
Copy Markdown
Member

Just checked again and seems to be working in Safari now. I don't think I had any extensions that would block it.

my $filename = 'screenshot-' . ($set ? $set->set_id . '-' . $problem->problem_id : 'problem') . '.png';
$filename =~ s/[^\w.-]/_/g;
$email->{parts} = [
Email::MIME->create(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like that this attaches the screenshot to the email twice. The primary reason that I do not like getting screenshots from students is because of how large it makes the email which makes downloading the email slower as well as causes extra processing by the email client to render the email. Attaching the image twice will not help with this, and is not necessary. See the method in lib/WeBWorK/TwoFactorAuthentication.pm that does this. This email is a bit different since it has a text and html part, but the technique still works.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I pushed a change to the email layout such that there is only one copy of a screenshot there now.

Also in looking at lib/WeBWorK/TwoFactorAuthentication.pm I saw your comment about using logo at tthe start of an image's Content-ID. In my testing, I am not needing to do that in order to successfully receive one of these Email Instructor emails at my personal gmail address. Do you think that comment is out of date? OR maybe only applies to QR code images?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am planning to do some more testing on that logo comment. That is behavior that I saw when testing at the time that I implemented two factor authentication. However, it is completely undocumented behavior for gmail. I suspect it might not be gmail that causes that issue, but perhaps something else in the email sending chain of events. In any case, don't worry about that for now.

@drgrice1

Copy link
Copy Markdown
Member

Pull request #3302 is the result of what I discovered regarding that comment about the logo cid. These emails should not be affected (although I haven't test this with actually sending emails on one of my MWSU servers yet where that happens). In any case these emails will need the Message-ID added. I will add that if this is merged before #3302. If #3302 is merged first, then we will need to remember to do that here.

@Alex-Jordan

Alex-Jordan commented Nov 20, 2026 via email

Copy link
Copy Markdown
Contributor Author

@drgrice1

Copy link
Copy Markdown
Member

Ignore my comment about either this or #3302 needing to be updated once the other is merged. For some reason I was thinking that this is adding a new email that is sent, but that is not the case. #3302 already adds the Message-ID to this email.

Yeah, perhaps the screenshot being shown on the feedback page is nice for students to see what they may not have in memory. Although it might have accessibility issues if considered in that way?

@drgrice1 drgrice1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this looks good.

I am not entirely fond of the mass of code in htdocs/js/Problem/problem.js to construct the screenshot. Hopefully the modern-screenshot library improves (or perhaps another better such library found) and eventually not all of that is needed.

I am also not entirely fond of the server side image processing to reduce the screenshot size. For that also, hopefully the modern-screenshot library improves and it generates smaller images to begin with in the future.

@somiaj

somiaj commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

In testing I noticed a few things.

  1. plotly3D.pl images don't seem to get picked up by the screenshot. Not a big deal just something I noticed.

  2. Should scaffolds be forced open before the screenshot? It could be info in closed ones could be needed, which won't be seen if they are closed (the student would have to know to open scaffolds before sending the screenshot if something useful was in them).

  3. In longer problems, the screenshot is fairly large, and having to scroll down past it to the "Send Email" button may not be needed, specifically if they are not including the screenshot. Maybe move the buttons, or provide a copy of them near the top for easier access.

  4. This seems to only take a screenshot of the problem area, so this means that if the problem had an error and there was warnings present on the page, they are no included in the screenshot. In my experience, the one time I like screenshots is often when there is an error in the problem, but I would need the errors included.

This isn't a feature I plan on using as of now (I might change my mind if I hear good use case stories about it). So don't change things just for me, these are just things I noticed for you to consider.

@drgrice1

Copy link
Copy Markdown
Member

I tested GraphTool and plots images, and they worked. I forgot to test plotly 3D images. I see that they are not coming through.

Scaffolds cannot be forced open. That doesn't make sense. If the intent of the problem is to reveal parts step by step, then how can you even suggest that? That would reveal parts of the problem the student is not supposed to see yet. Note that the unopened parts of a scaffold are not even in the DOM (they are nowhere client side), and the javascript has no hope of including those in the screenshot.

@somiaj

somiaj commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

I mean whatever scaffolds can be opened. So it would only be able to open all the ones up to where the student got stuck.

@drgrice1

Copy link
Copy Markdown
Member

One thing I noticed with GraphTool problems is that the screenshot generate was pretty slow, and is slower when more things have been graphed. It takes several seconds before the form is submitted while the screenshot is being generated. Since this is

@drgrice1

Copy link
Copy Markdown
Member

Oops. Accidental button press mid comment.

I meant to add, that since the screenshot is being generated by javascript, there is no indication to the user as to why the page is just sitting there doing nothing like a slow server response. For a slow server response, most browsers give a loading indicators. But with this there is nothing. Perhaps a loading overlay or something could be added. Otherwise you might have users start to click the button several times thinking that it didn't take the first time.

@somiaj

somiaj commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

For scaffolds, if a student is stuck on section 3, section 1 and 2 are completed and closed by default. So it might be useful to see the student answers in the first two scaffolds to help support the student in the third. So open all scaffolds that could be opened could be useful in the screenshot.

@drgrice1

Copy link
Copy Markdown
Member

Yeah, in that case the closed scaffolds could be include, but I think that will be problematic to actually accomplish with this.

Also, note that this depends on the settings for the scaffold. The settings I use keep the previously answered scaffolds open.

@somiaj

somiaj commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

And students can open/closed scaffolds, so what is actually shown in the screenshot could be dependent on what the student has done. If it isn't easy to open them, I wouldn't worry about it to much. I was just commenting it could be useful to have them opened in the screenshot.

@Alex-Jordan

Alex-Jordan commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

plotly3D.pl images don't seem to get picked up by the screenshot. Not a big deal just something I noticed.

I'm looking into that. Unfortunately it will probably mean more special code for making up for a modern-screenshot deficiency.

Should scaffolds be forced open before the screenshot?

I don't think so. The idea is a screenshot to show what the student was seeing at that moment. And to give the instructor an understanding at a glance about which exercise the message is about. If there's a need to really dig into the exercise, the instructor will need to log in and look there.

Maybe move the buttons, or provide a copy of them near the top for easier access.

I'll move the button.

if the problem had an error and there was warnings present on the page, they are no included in the screenshot.

If the problem actually has errors such that it fails to render, then those errors are send instead of any screenshot. If there are less severe perl warnings, what do we think should happen? There are two kinds: kinds a student would see and kinds that would only be revealed to an instructor. What behavior do we want?

@Alex-Jordan

Copy link
Copy Markdown
Contributor Author

plotly draws in canvas elements, and that was not covered well by this. But it will be with my next push.

graphTool and other things draw svg, and modern-screenshot handles that slowly. I'm going to try having svg's be exported to png from the student's screen first, and then plant those inside the screenshot rather than redo the svgs from graphTool, etc.

Alex-Jordan and others added 5 commits November 21, 2026 13:44
If `$mail{feedbackScreenshot}` is set in site.conf (it is disabled by
default), then when the "Email Instructor" button is clicked on a problem
page, a screenshot of the rendered problem is taken in the browser and sent to
the feedback page. The feedback page shows the screenshot with a checkbox that
allows the student to choose to include it. The checkbox is unchecked by
default, so that screenshots are only sent when they would be helpful. The
screenshot is embedded in the html version of the email (in a
multipart/related part referenced by its content id), and attached to the text
version of the email (in a multipart/mixed part). Screenshots larger than the
maximum attachment size are not included.

The screenshot is taken with the modern-screenshot javascript package. The
following issues with that package are worked around:

* Pseudo elements whose content is an image (such as the icons in the answer
  feedback buttons) are rendered as the text of the image url.
* Open popovers (such as answer feedback popovers) are positioned relative to
  their offset parent, which is often outside of the problem body, and so are
  not in the right place or not in the screenshot at all. The screenshot is
  also expanded to include popovers that extend outside of the problem body.
* An overflow of visible is not copied for svg elements, and so parts of
  MathJax output that extend outside of the svg (for example the tail of a Q)
  are clipped.

The PNG images created by browsers are not well compressed. So the screenshot
is converted to a palette image with at most 256 colors and compressed with
GD when it is received by the server. This reduces the size of a typical
screenshot to about 30% of the original size with no visible difference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t fail to render.

If a problem fails to render, then the first 20 lines of the PG error message
are passed to the feedback page when the "Email Instructor" button is clicked,
and are included in the feedback email. A screenshot of the problem is not
taken in this case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…screenshots.

modern-screenshot does not copy the current state of checkboxes, radio
buttons, or select options to the cloned problem. In addition, Firefox does
not render checkboxes and radio buttons in the screenshot. So checkboxes and
radio buttons are replaced in the clone with drawn elements that show their
current state, and the selected attribute is set on select options that are
currently selected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Alex-Jordan

Copy link
Copy Markdown
Contributor Author

OK, the changes recently discussed are here. Two things not here are:

  1. What to do when there are perl warnings. Either the kinds that students see or the kinds they do not.
  2. A "page is loading" indicator. The other changes here noticeably sped things up for me with the complicated graphTool image I was testing with. If you think a "page is loading" indicator would still be good, I can add that.

Alex-Jordan and others added 2 commits November 21, 2026 13:51
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…shot code.

Screenshots of problems are generated faster, particularly for problems with
graphs and images and in Firefox and Safari. The code is also simplified and
more robust when taking a screenshot times out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Alex-Jordan

Copy link
Copy Markdown
Contributor Author

I added one more commit so that the email shows perl warnings that the student saw.

There is also a note to the student when composing the message that the warnings will be included in the email. So they don't need to copy those warnings into their message.

Test this out by putting warn "Test Perl warning."; or something into a problem.

@drgrice1 drgrice1 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am starting to question this pull request now. The amount of code and hacks in the problem.js file that are needed to get the screenshots to actually work well is really concerning. Furthermore, I am starting to look closer at that code, and am seeing things that are being abstracted nonsensically. These are examples of AI really not understanding what it is doing, but just applying heuristics and guess work. One abstraction that is clearly not needed is the createMarker method. Defining it in that way is an absurd abstraction of a simple array.

I am not really seeing any difference in speed for screenshots with the GraphTool problems with the latest changes. Also, the plotly3d screenshots are now working, but those are even slower to generate than the GraphTool problems.

@Alex-Jordan

Alex-Jordan commented Nov 22, 2026 via email

Copy link
Copy Markdown
Contributor Author

@drgrice1

Copy link
Copy Markdown
Member

Yeah, I can help with cleaning up the JavaScript. Sometimes the code generated by AI is painful to read and understand because it adds convoluted code to achieve a simple end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants