What are you using <canvas> for with a simple script like that. I also wouldn't call it artificial intelligence when there are only eleven combinations possible in the entire game.
for a working script that you can examine to see one way to do it (the player wins code is commented out as it will never be run anyway as the best the player can get with that code is a draw). As you can see the script is not very long because there are not that many alternatives to check - most being rotations of one of the eleven positions.
I know there are only eleven possibilities in the game because thirty five years ago a friend and I set up a "matchbox" computer consisting of eleven matchboxes with positions drawn on to with the matchboxe's possible moves drawn in different colours and one or at most two coloured matches inside to select the "computer's" move. So perhaps my friend and I invented intelligent matchboxes since the best you could do against them was a draw - provided you wanted to play the one game they knew how to play.