Activate the frontmost Safari and run Javascript I'm trying to run Javascript on the Safari, whose frontmost is true. 

tell (application "Safari" whose frontmost is true) to do JavaScript theScript in current tab of first window


But I get an error like this:

execution error: Can’t get application "System Events" whose frontmost of it = true. Access not allowed. (-1723)


where I'm making mistake?
Your script is trying to tell s.th. to a Safari application allegedly already "frontmost". Is it?!?
You can only identify or activate an unknown element by property ("whose ... is ...")
This will do: the first application whose ...

If you WANT "Safari" to become "frontmost" you'd  better write:

tell application "Safari"
    activate
    do JavaScript theScript in current tab of first window
end tell