Workaround to post inline JS code at any time in D8? In Drupal 7 this worked:

drupal_add_js("jQuery(document).ready(function () { console.log('Hello!'); });", 'inline');


which aims to print the messages from the PHP code onto DevTools JS console in realtime (on each page request), however in Drupal 8 the above function has been removed in favor of #attached.

I'm aware that I should use #attached in my library, but sometimes the $form is not accessible and I'd like to invoke some JS code on certain functions and conditions (e.g. in hook_tokens) for debugging purposes (like injecting some PHP variables into the JS message during the processing).

Is there any other way of doing this?
Sometimes the $form is not accessible and  I'd like to invoke some JS code on certain functions and conditions for debugging purposes.

Not sure if this will do for you, but posting this anyways just in case.
I use Greasemonkey for Firefox and Tampermonkey for Chrome which allows your browser to load any js file that you write locally on this app/your computer.