Bird
0
0

What will happen if a Cypress plugin tries to access a browser-only API inside the plugin function?

medium📝 Predict Output Q5 of 15
Cypress - Plugins and Ecosystem
What will happen if a Cypress plugin tries to access a browser-only API inside the plugin function?
AIt will convert the API call to a plugin task automatically
BIt will throw a runtime error because plugins run in Node.js, not the browser
CIt will silently ignore the call and continue
DIt will work normally because Cypress bridges browser and Node.js
Step-by-Step Solution
Solution:
  1. Step 1: Identify the environment plugins run in

    Cypress plugins run in Node.js, which does not have browser APIs like window or document.
  2. Step 2: Understand consequences of accessing browser-only APIs in plugins

    Trying to use browser APIs in plugins causes runtime errors because those APIs are undefined in Node.js.
  3. Final Answer:

    It will throw a runtime error because plugins run in Node.js, not the browser -> Option B
  4. Quick Check:

    Plugin environment = Node.js, no browser APIs [OK]
Quick Trick: Plugins run in Node.js, not browser [OK]
Common Mistakes:
  • Assuming browser APIs work in plugins
  • Thinking Cypress auto-converts API calls
  • Believing errors are ignored silently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes