<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def open_in_browser(self, session, output_filename=None):
 """ Open the rendered HTML in a webbrowser. If output_filename=None (the default), a tempfile is used. The filename of the HTML file is returned. """

        if output_filename is None:
            output_file = tempfile.NamedTemporaryFile(suffix='.html', delete=False)
            output_filename = output_file.name
            with codecs.getwriter('utf-8')(output_file) as f:
                f.write(self.render(session))
        else:
            with codecs.open(output_filename, 'w', 'utf-8') as f:
                f.write(self.render(session))

        from pyinstrument.vendor.six.moves import urllib
        url = urllib.parse.urlunparse(('file', '', output_filename, '', '', ''))
        webbrowser.open(url)
        return output_filename