That's the tty or the thing on the other end of the pty (ie your VTE like Xterm) which would have to do that. The shell has no access to any of it.
There is an xterm command for writing the scrollback buffer to a file so in theory if you wanted a hack to enable it today you could use that + grep (or even trigger it with something xdotool if you wanted to automate it.)
There is an xterm command for writing the scrollback buffer to a file so in theory if you wanted a hack to enable it today you could use that + grep (or even trigger it with something xdotool if you wanted to automate it.)