Sorry for the necro post, but this is the google result for the problem and I've found a solution that works for us.
In the theme's config.php file, adjust the incourse array from:
'incourse' => array(
'file' => 'general.php',
'regions' => array('side-pre', 'side-post'),
'defaultregion' => 'side-pre',
),
to
'incourse' => array(
'file' => 'general.php',
'options' => array('nologinlinks'=>true),
'regions' => array('side-pre', 'side-post'),
'defaultregion' => 'side-pre',
),
i.e. add the options array (or add nologinlinks to the existing array if you have one)
This will remove the "(Log out)" link in the header and footer of the page while in a course, so the student can't log out without exiting the activity and hence don't generate the error where the javascript is attempting to write to a closed connection.