Execute code before script is previewed


So, i have developed a plugin that is executed whenever the user runs the code. It is working perfectly well in IntelliJ and PyCharm. But now I need to use it also with PHPStorm... The problem is that the "Run" action runs the script code in the IDE, but I need to execute the code in the Browser...

I saw that it is possible to create a run configuration for a Web Application,  the problem is that it should work with the file that is currently open in the editor. So... the "preview in browser" option (click on the browser icon) seems to be the best solution...

My question is: how do i execute my code when the user clicks on the browser icon?

For the "Run"... option I am using this code:

public class CodeInsights extends AbstractProjectComponent {

   public CodeInsights(@NotNull Project project) {


   project.getMessageBus().connect().subscribe(ExecutionManager.EXECUTION_TOPIC, new ExecutionListener() {
      public void processStarted(@NotNull String executorId, @NotNull ExecutionEnvironment env, @NotNull ProcessHandler handler) {


           sendText(document.getText(), project);

   private void sendText(String text, Project project) {

Best regards,




Please sign in to leave a comment.