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

[Bug]: #12390

Closed
1 of 2 tasks
fe2-Nyxar opened this issue May 5, 2024 · 7 comments
Closed
1 of 2 tasks

[Bug]: #12390

fe2-Nyxar opened this issue May 5, 2024 · 7 comments
Labels
bug disable-analyzer Disables the automatic workflow that tries to reproduce bug reports needs-feedback not-reproducible

Comments

@fe2-Nyxar
Copy link

fe2-Nyxar commented May 5, 2024

Minimal, reproducible example

Main file ( "Index.js" type ="module")

import puppeteer from "puppeteer";
import { getTheAudio } from "./getTheAudio.mjs";
const browser = await puppeteer.launch({
  headless: false,
});
const page = await browser.newPage();
await page.goto("https://app.ofppt-langues.ma/platform/#/learning-path/mission/DONNER_SES_INFORMATIONS_PERSONNELLES_A1/lesson/FR_FR_A1_GRAMMAR_DEMANDER_ET_DONNER_LA_DATE/activity/FR_FR_A1_GRAMMAR_DEMANDER_ET_DONNER_LA_DATE_EXERCISE_DEMANDER_ET_DONNER_LA_DATE_2/exercise/item/0");

await getTheAudio(page);

The Function: "getTheAudio.mjs"

import fs from "fs";

export async function getTheAudio(page) {
  page.on("response", async (response) => {
    const url = response.url();
    const extension = url.split(".").pop();
    const contentType = response.headers()["content-type"];
    if (extension === "blu" && contentType === "audio/mpeg") {
      try {
        let audioBlu = await response.buffer();
        fs.writeFileSync("./AudioJunk/generatedAudio.mp3", audioBlu);
      } catch (error) {
        console.error("the error is: ", error);
        return false;
      }
    }
  });
}

Error string

no error

Bug behavior

  • Flaky
  • PDF

Background

Bug Report: Inconsistent Detection of Responses in Puppeteer

Description:

The getTheAudio function is designed to catch responses with a specific content type (audio/mpeg) and save them to a file. However, there are instances where the desired response (.blu file) is not detected by Puppeteer's page.on("response") event handler, leading to inconsistent behavior.

Observations:

  • The issue was investigated using Chrome DevTools' Network tab to monitor network activity.
  • In some cases, the desired response was not displayed in the Network tab despite being expected.
  • Exporting a .har file from the Network tab revealed that the response was indeed present, even though it was not detected by Puppeteer or shown in the Chrome DevTools Network tab.

Expectation

I expected that response to get detected everytime.

Reality

I receive a bunch of .blu files as a response but it's always the first file that doesn't get detected , sometimes it does, sometimes it doesn't

Puppeteer configuration file (if used)

No response

Puppeteer version

22.7.0

Node version

20.12.2

Package manager

npm

Package manager version

10.2.4

Operating system

Windows

Copy link

github-actions bot commented May 5, 2024

This issue has an invalid Node.js version: 20.12.2. Versions must follow SemVer formatting. Please update the form with a valid version.


Analyzer run

@OrKoN
Copy link
Collaborator

OrKoN commented May 5, 2024

Please include a test page into the example and the complete script demonstrating the issue.

@fe2-Nyxar
Copy link
Author

fe2-Nyxar commented May 5, 2024

I just added more code for a better understanding of the issue and changed the Reality paragraph, and I didn't include the URL cause it requires a login.
and for tests, I didn't run any tests on it, it was just my observations to the issue

@OrKoN
Copy link
Collaborator

OrKoN commented May 6, 2024

Please create a test page that shows the problem. Without it there is no way to debug the issue.

@OrKoN
Copy link
Collaborator

OrKoN commented May 6, 2024

await page.goto("SomeUrl");

await getTheAudio(page);

the way this is written it looks like a race condition since all requests can already fire by the time getTheAudio is called. So without an executable example it is not possible to debug.

@OrKoN OrKoN added needs-feedback not-reproducible disable-analyzer Disables the automatic workflow that tries to reproduce bug reports and removed invalid labels May 6, 2024
@fe2-Nyxar
Copy link
Author

fe2-Nyxar commented May 9, 2024

Idk what else I should provide cause I'm not that smart :), and the reason I didn't provide more code is gonna distract you from the issue, so I tried to keep it minimal as much as possible, and for the URL It requires a login, cause it's a school site, I hope that cleared why I couldn't share any more details, and sorry for the inconvenience

@fe2-Nyxar
Copy link
Author

fe2-Nyxar commented May 9, 2024

since I'm Stupid I asked chatgpt to generate a test:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Puppeteer Audio Response Test Page</title>
</head>
<body>
    <h1>Puppeteer Audio Response Test Page</h1>
    <button id="trigger-response">Trigger Audio Response</button>

    <script>
        document.getElementById('trigger-response').addEventListener('click', async () => {
            // Simulate fetching an audio response
            const response = await fetch('/fake-audio-response');

            // Simulate processing the response
            if (response.ok) {
                // Simulate extracting the audio data
                const audioBlob = await response.blob();
                // Simulate playing the audio
                const audioUrl = URL.createObjectURL(audioBlob);
                const audioElement = new Audio(audioUrl);
                audioElement.play();
            } else {
                console.error('Failed to fetch audio response');
            }
        });
    </script>
</body>
</html>

@fe2-Nyxar fe2-Nyxar closed this as not planned Won't fix, can't repro, duplicate, stale May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug disable-analyzer Disables the automatic workflow that tries to reproduce bug reports needs-feedback not-reproducible
Projects
None yet
Development

No branches or pull requests

2 participants