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

Dev client worker capturing /_favicon/ request in chrome manifest v3 #618

Open
1 of 2 tasks
stevezhu opened this issue Dec 26, 2022 · 4 comments · May be fixed by #819
Open
1 of 2 tasks

Dev client worker capturing /_favicon/ request in chrome manifest v3 #618

stevezhu opened this issue Dec 26, 2022 · 4 comments · May be fixed by #819
Labels
bug Something isn't working

Comments

@stevezhu
Copy link

stevezhu commented Dec 26, 2022

Build tool

Vite

Where do you see the problem?

  • In the browser
  • In the terminal

Describe the bug

I'm attempting to use the /_favicon/ api from chrome manifest v3 shown here:
https://github.com/GoogleChrome/chrome-extensions-samples/tree/main/api/favicon

It seems that due to the hmr client worker capturing all requests during dev, the requests to /_favicon/ are also being captured instead of being handled by chrome.

Reproduction

Use https://github.com/GoogleChrome/chrome-extensions-samples/tree/main/api/favicon with @crxjs/vite-plugin in dev mode.

Logs

Failed request (when client worker is capturing requests):

Request URL: http://localhost:5173/_favicon/?pageUrl=https%3A%2F%2Fwww.google.com%2F&size=64&t=1672027377433
Request Method: GET
Status Code: 404 Not Found
Remote Address: 127.0.0.1:5173
Referrer Policy: strict-origin-when-cross-origin

Expected successful request:

Request URL: chrome-extension://<id>/_favicon/?pageUrl=https%3A%2F%2Fwww.google.com%2F&size=64
Request Method: GET
Status Code: 200 OK (from memory cache)
Referrer Policy: strict-origin-when-cross-origin

System Info

System:
    OS: macOS 13.0.1
    CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
    Memory: 453.57 MB / 16.00 GB
    Shell: 3.5.1 - /usr/local/bin/fish
  Binaries:
    Node: 18.8.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 8.18.0 - /usr/local/bin/npm
  npmPackages:
    @crxjs/vite-plugin: 2.0.0-beta.9 => 2.0.0-beta.9
    vite: ^4.0.1 => 4.0.1

Severity

annoyance

@stevezhu stevezhu changed the title Dev client worker capturing /_favicon/ request Dev client worker capturing /_favicon/ request in manifest v3 Dec 26, 2022
@stevezhu stevezhu changed the title Dev client worker capturing /_favicon/ request in manifest v3 Dev client worker capturing /_favicon/ request in chrome manifest v3 Dec 26, 2022
@jacksteamdev jacksteamdev added the bug Something isn't working label Mar 26, 2023
@zhaoguangyue
Copy link

When is it expected to be repaired

@mj2ks
Copy link

mj2ks commented Aug 12, 2023

@stevezhu Found a solution?

@alajmo alajmo linked a pull request Nov 2, 2023 that will close this issue
@alajmo
Copy link

alajmo commented Nov 2, 2023

I included a fix to this issue, if it's not merged, you can link it locally, just make these changes:

async function sendToServer(url: URL): Promise<Response> {
  if (url.href.includes('/_favicon/')) {
    const response = await fetch(url.href)
    return new Response(response.body, {
      headers: {
        'Content-Type': response.headers.get('Content-Type') ?? 'text/javascript',
      },
   })
  }

  // change the url to point to the dev server
  url.protocol = 'http:'
  url.host = 'localhost'
  url.port = __SERVER_PORT__
  // add a timestamp to force Chrome to do a new request
  url.searchParams.set('t', Date.now().toString())
  // URLSearchParams adds "=" to every empty param & vite doesn't like it
  const response = await fetch(url.href.replace(/=$|=(?=&)/g, ''))
  // circumvent extension CSP by creating response from extension origin
  return new Response(response.body, {
    headers: {
      'Content-Type': response.headers.get('Content-Type') ?? 'text/javascript',
    },
  })
}

HarryYu02 added a commit to HarryYu02/booktab that referenced this issue Apr 26, 2024
@gp0119
Copy link

gp0119 commented Oct 11, 2024

The problem still exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants