Use add_action to run a script, but only on the post editor page

The function get_current_screen gets the current screen object.

I used a condition inside my callback function to return a script only if the screen id == post:

if( $currentScreen->id === "post" ) {
        echo "
        <script>
        </script>";
    }

https://developer.wordpress.org/reference/functions/get_current_screen/