Copy permalink to clipboard automatically when publish/update posts?

Finally, I did it! Use the post_updated_messages hook instead.

add_filter( 'post_updated_messages', function( $messages )
{
    // Get the permalink
    $link = esc_url( get_permalink($post_ID) );

    // Copy the permalink automatically
    $autocopy = '<script type="text/javascript">navigator.clipboard.writeText("https://wordpress.stackexchange.com/questions/367921/%s");</script>';

    // `6` is for publishing
    $messages['post'][6] = sprintf( __('Post published. <a href="https://wordpress.stackexchange.com/questions/367921/%s">View post</a>'. $autocopy), $link, $link);

    // `1` is for updating
    $messages['post'][1] = sprintf( __('Post updated. <a href="https://wordpress.stackexchange.com/questions/367921/%s">View post</a>'. $autocopy), $link, $link);

    return $messages;
} );