Electron window shows a screenshot of the screen











up vote
0
down vote

favorite












So I have an electron app named main.js which I start with npm start. I've set the start script in package.json to electron main.js and have also tried electron .. When running npm start, everything starts without any errors but the electron window only shows a snapshot of what was on the screen when I started it. I've tried refreshing it but nothing seems to work. Here is how it looks:
Image
It should view localhost:3001 but it doesn't. I've also tried to run electron . directly in the terminal but that gives me electron: command not found. When running ./node_modules/electron/dist/electron . it starts as it should but the same problem occurs. Here is main.js:



const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const core = require('./app');

let mainWindow

function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: { webSecurity: false },
nodeIntegration: false,
})

mainWindow.loadURL('http://localhost:3001');

// mainWindow.setFullScreen(true)

// mainWindow.setMenu(null);

mainWindow.webContents.openDevTools()

mainWindow.on('closed', function () {
mainWindow = null
})

console.log('Electron window ready')
}

app.on('ready', createWindow)

app.on('window-all-closed', function () {
app.quit()
})

core.start()









share|improve this question


























    up vote
    0
    down vote

    favorite












    So I have an electron app named main.js which I start with npm start. I've set the start script in package.json to electron main.js and have also tried electron .. When running npm start, everything starts without any errors but the electron window only shows a snapshot of what was on the screen when I started it. I've tried refreshing it but nothing seems to work. Here is how it looks:
    Image
    It should view localhost:3001 but it doesn't. I've also tried to run electron . directly in the terminal but that gives me electron: command not found. When running ./node_modules/electron/dist/electron . it starts as it should but the same problem occurs. Here is main.js:



    const electron = require('electron');
    const app = electron.app;
    const BrowserWindow = electron.BrowserWindow;
    const core = require('./app');

    let mainWindow

    function createWindow() {
    mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: { webSecurity: false },
    nodeIntegration: false,
    })

    mainWindow.loadURL('http://localhost:3001');

    // mainWindow.setFullScreen(true)

    // mainWindow.setMenu(null);

    mainWindow.webContents.openDevTools()

    mainWindow.on('closed', function () {
    mainWindow = null
    })

    console.log('Electron window ready')
    }

    app.on('ready', createWindow)

    app.on('window-all-closed', function () {
    app.quit()
    })

    core.start()









    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      So I have an electron app named main.js which I start with npm start. I've set the start script in package.json to electron main.js and have also tried electron .. When running npm start, everything starts without any errors but the electron window only shows a snapshot of what was on the screen when I started it. I've tried refreshing it but nothing seems to work. Here is how it looks:
      Image
      It should view localhost:3001 but it doesn't. I've also tried to run electron . directly in the terminal but that gives me electron: command not found. When running ./node_modules/electron/dist/electron . it starts as it should but the same problem occurs. Here is main.js:



      const electron = require('electron');
      const app = electron.app;
      const BrowserWindow = electron.BrowserWindow;
      const core = require('./app');

      let mainWindow

      function createWindow() {
      mainWindow = new BrowserWindow({
      width: 800,
      height: 600,
      webPreferences: { webSecurity: false },
      nodeIntegration: false,
      })

      mainWindow.loadURL('http://localhost:3001');

      // mainWindow.setFullScreen(true)

      // mainWindow.setMenu(null);

      mainWindow.webContents.openDevTools()

      mainWindow.on('closed', function () {
      mainWindow = null
      })

      console.log('Electron window ready')
      }

      app.on('ready', createWindow)

      app.on('window-all-closed', function () {
      app.quit()
      })

      core.start()









      share|improve this question













      So I have an electron app named main.js which I start with npm start. I've set the start script in package.json to electron main.js and have also tried electron .. When running npm start, everything starts without any errors but the electron window only shows a snapshot of what was on the screen when I started it. I've tried refreshing it but nothing seems to work. Here is how it looks:
      Image
      It should view localhost:3001 but it doesn't. I've also tried to run electron . directly in the terminal but that gives me electron: command not found. When running ./node_modules/electron/dist/electron . it starts as it should but the same problem occurs. Here is main.js:



      const electron = require('electron');
      const app = electron.app;
      const BrowserWindow = electron.BrowserWindow;
      const core = require('./app');

      let mainWindow

      function createWindow() {
      mainWindow = new BrowserWindow({
      width: 800,
      height: 600,
      webPreferences: { webSecurity: false },
      nodeIntegration: false,
      })

      mainWindow.loadURL('http://localhost:3001');

      // mainWindow.setFullScreen(true)

      // mainWindow.setMenu(null);

      mainWindow.webContents.openDevTools()

      mainWindow.on('closed', function () {
      mainWindow = null
      })

      console.log('Electron window ready')
      }

      app.on('ready', createWindow)

      app.on('window-all-closed', function () {
      app.quit()
      })

      core.start()






      javascript node.js npm electron






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 2 at 17:32









      Hannes Skoog

      31




      31
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          It seems you didn't install Electron globally, for that you need to run npm install -g Electron



          Replace mainWindow.loadURL('http://localhost:3001'); With:



          mainWindow.loadURL(
          url.format({
          pathname: path.join(__dirname, "index.html"),
          protocol: "file:",
          slashes: true
          })
          );





          share|improve this answer




























            up vote
            0
            down vote













            You have not shared your package.json file, but I will guess you did not run npm install --save electron in your terminal.



            Also, instead of:



            const electron = require('electron');
            const app = electron.app;
            const BrowserWindow = electron.BrowserWindow;


            you want to write it like so:



            const electron = require('electron');
            const { app, BrowserWindow } = electron;


            I would review ES6 destructuring and unless you did not share the code with us, you should start your electron project by assuring that the app object is ready and loading your file like so:



            let mainWindow;

            app.on('ready', () => {
            mainWindow = new BrowserWindow({});
            mainWindow.loadURL(`file://${__dirname}/main.html`);
            });


            You will notice I declared an empty mainWindow variable to take care of any scoping issues you may have as you may have to use mainWindow in other functions as well.






            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53123358%2felectron-window-shows-a-screenshot-of-the-screen%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              0
              down vote













              It seems you didn't install Electron globally, for that you need to run npm install -g Electron



              Replace mainWindow.loadURL('http://localhost:3001'); With:



              mainWindow.loadURL(
              url.format({
              pathname: path.join(__dirname, "index.html"),
              protocol: "file:",
              slashes: true
              })
              );





              share|improve this answer

























                up vote
                0
                down vote













                It seems you didn't install Electron globally, for that you need to run npm install -g Electron



                Replace mainWindow.loadURL('http://localhost:3001'); With:



                mainWindow.loadURL(
                url.format({
                pathname: path.join(__dirname, "index.html"),
                protocol: "file:",
                slashes: true
                })
                );





                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  It seems you didn't install Electron globally, for that you need to run npm install -g Electron



                  Replace mainWindow.loadURL('http://localhost:3001'); With:



                  mainWindow.loadURL(
                  url.format({
                  pathname: path.join(__dirname, "index.html"),
                  protocol: "file:",
                  slashes: true
                  })
                  );





                  share|improve this answer












                  It seems you didn't install Electron globally, for that you need to run npm install -g Electron



                  Replace mainWindow.loadURL('http://localhost:3001'); With:



                  mainWindow.loadURL(
                  url.format({
                  pathname: path.join(__dirname, "index.html"),
                  protocol: "file:",
                  slashes: true
                  })
                  );






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 3 at 6:11









                  matrixersp

                  315




                  315
























                      up vote
                      0
                      down vote













                      You have not shared your package.json file, but I will guess you did not run npm install --save electron in your terminal.



                      Also, instead of:



                      const electron = require('electron');
                      const app = electron.app;
                      const BrowserWindow = electron.BrowserWindow;


                      you want to write it like so:



                      const electron = require('electron');
                      const { app, BrowserWindow } = electron;


                      I would review ES6 destructuring and unless you did not share the code with us, you should start your electron project by assuring that the app object is ready and loading your file like so:



                      let mainWindow;

                      app.on('ready', () => {
                      mainWindow = new BrowserWindow({});
                      mainWindow.loadURL(`file://${__dirname}/main.html`);
                      });


                      You will notice I declared an empty mainWindow variable to take care of any scoping issues you may have as you may have to use mainWindow in other functions as well.






                      share|improve this answer

























                        up vote
                        0
                        down vote













                        You have not shared your package.json file, but I will guess you did not run npm install --save electron in your terminal.



                        Also, instead of:



                        const electron = require('electron');
                        const app = electron.app;
                        const BrowserWindow = electron.BrowserWindow;


                        you want to write it like so:



                        const electron = require('electron');
                        const { app, BrowserWindow } = electron;


                        I would review ES6 destructuring and unless you did not share the code with us, you should start your electron project by assuring that the app object is ready and loading your file like so:



                        let mainWindow;

                        app.on('ready', () => {
                        mainWindow = new BrowserWindow({});
                        mainWindow.loadURL(`file://${__dirname}/main.html`);
                        });


                        You will notice I declared an empty mainWindow variable to take care of any scoping issues you may have as you may have to use mainWindow in other functions as well.






                        share|improve this answer























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          You have not shared your package.json file, but I will guess you did not run npm install --save electron in your terminal.



                          Also, instead of:



                          const electron = require('electron');
                          const app = electron.app;
                          const BrowserWindow = electron.BrowserWindow;


                          you want to write it like so:



                          const electron = require('electron');
                          const { app, BrowserWindow } = electron;


                          I would review ES6 destructuring and unless you did not share the code with us, you should start your electron project by assuring that the app object is ready and loading your file like so:



                          let mainWindow;

                          app.on('ready', () => {
                          mainWindow = new BrowserWindow({});
                          mainWindow.loadURL(`file://${__dirname}/main.html`);
                          });


                          You will notice I declared an empty mainWindow variable to take care of any scoping issues you may have as you may have to use mainWindow in other functions as well.






                          share|improve this answer












                          You have not shared your package.json file, but I will guess you did not run npm install --save electron in your terminal.



                          Also, instead of:



                          const electron = require('electron');
                          const app = electron.app;
                          const BrowserWindow = electron.BrowserWindow;


                          you want to write it like so:



                          const electron = require('electron');
                          const { app, BrowserWindow } = electron;


                          I would review ES6 destructuring and unless you did not share the code with us, you should start your electron project by assuring that the app object is ready and loading your file like so:



                          let mainWindow;

                          app.on('ready', () => {
                          mainWindow = new BrowserWindow({});
                          mainWindow.loadURL(`file://${__dirname}/main.html`);
                          });


                          You will notice I declared an empty mainWindow variable to take care of any scoping issues you may have as you may have to use mainWindow in other functions as well.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 12 at 2:20









                          Daniel

                          1,64521228




                          1,64521228






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53123358%2felectron-window-shows-a-screenshot-of-the-screen%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Bressuire

                              Vorschmack

                              Quarantine