Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to load URL: app://-/ with error: ERR_FILE_NOT_FOUND #44

Closed
itsonlyjames opened this issue Sep 5, 2024 · 4 comments
Closed

Failed to load URL: app://-/ with error: ERR_FILE_NOT_FOUND #44

itsonlyjames opened this issue Sep 5, 2024 · 4 comments

Comments

@itsonlyjames
Copy link
Contributor

itsonlyjames commented Sep 5, 2024

Completely stumped here and seeking some help—I've updated to the latest version and so am now using imports instead of requires.

Nothing else has changed except for updating the relevant packages and changing from require to import, yet I'm receiving this error..

image

I did investigate #29 however that seems due to a change in build structure, whereas none of my structure has changed. I do see it being from a long time ago however.

Here is my minimal electron.js reproducible code:

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

const serveURL = serve({ directory: './' })
let mainWindow

function createWindow() {
    let windowState = windowStateManager({
        defaultWidth: 800,
        defaultHeight: 600
    })

    const mainWindow = new BrowserWindow({
        backgroundMaterial: 'none',
        backgroundColor: 'rgba(0,0,0,0)',
        titleBarStyle: process.platform === 'darwin' ? 'hidden' : 'default',
        autoHideMenuBar: true,
        trafficLightPosition: {
            x: 14,
            y: 14
        },
        center: true,
        minHeight: 450,
        minWidth: 500,
        webPreferences: {
            contextIsolation: true,
            spellcheck: false,
            devTools: true,
            preload: path.join(__dirname, 'preload.cjs')
        },
        icon: path.join(__dirname, '../static/icon.png'),
        x: windowState.x,
        y: windowState.y,
        width: windowState.width,
        height: windowState.height
    })

    windowState.manage(mainWindow)

    mainWindow.once('ready-to-show', () => {
        mainWindow.show()
        mainWindow.focus()
    })

    mainWindow.on('close', () => {
        windowState.saveState(mainWindow)
    })

    mainWindow.webContents.session.protocol.registerFileProtocol(
        'media',
        (request, callback) => {
            const pathname = decodeURIComponent(
                request.url.replace('media://', '')
            )
            callback(pathname)
        }
    )

    mainWindow.webContents.setWindowOpenHandler(({ url }) => {
        shell.openExternal(url)
        return { action: 'deny' }
    })

    return mainWindow
}

async function loadStatic(mainWindow) {
    await serveURL(mainWindow)
        .then((url) => {
            mainWindow.loadURL(url)
        })
        .catch((e) => {
            console.log('Error: ', e)
        })
}

async function createMainWindow() {
    mainWindow = createWindow()
    mainWindow.once('close', () => {
        mainWindow = null
    })
    await loadStatic(mainWindow)
}

Build.config

{
  "directories": {
    "output": "../dist"
  },
  "files": [
    "src/electron.js",
    "src/preload.cjs",
    "!**/ffprobe-static/bin/**/*",
    "**/ffprobe-static/bin/${platform}/${arch}/ffprobe",
    {
      "from": "build",
      "to": ""
    }
  ],
  "mac": {
    "icon": "icon.png"
  }
}

Directory structure:

.
├── Client/
│   ├── build/
│   │   ├── _app/
│   │   └── index.html
│   ├── src/
│   │   ├── app.html
│   │   ├── electron.js
│   │   └── preload.cjs
│   └── build.config.json
└── dist/

Any help is greatly appreciated!

@k7sleeper
Copy link

k7sleeper commented Sep 11, 2024

That's due to line 42 of index.js:

const isSafe = relativePath && !relativePath.startsWith('..') && !path.isAbsolute(relativePath);

should be changed to

const isSafe = !relativePath.startsWith('..') && !path.isAbsolute(relativePath);

as relativePath can never be null or undefined but is '' for the first request.

You may also change line 42 to

const isSafe = relativePath != null && !relativePath.startsWith('..') && !path.isAbsolute(relativePath);

@itsonlyjames
Copy link
Contributor Author

@k7sleeper that suggestion works for me and I thank you for that.

Ought this be a fix in the codebase?

@k7sleeper
Copy link

k7sleeper commented Sep 12, 2024

@itsonlyjames Yes, This should be a fix.

@itsonlyjames
Copy link
Contributor Author

@k7sleeper #45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants