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

feat: Support returning values from scripts executed with the scripting API #624

Merged
merged 5 commits into from
May 3, 2024

Conversation

aklinker1
Copy link
Collaborator

@aklinker1 aklinker1 commented Apr 19, 2024

This closes #622.

Adds support for returning values from both content scripts (likely with registration: 'runtime', but not necessarily) and unlisted scripts.

Just return a value from the script's main function and the background will get the value, even if it's an async function.

// Sync function's work
export default defineUnlistedScript(() => {
  // ...
  return "return value"
});

// Async functions also work
export default defineUnlistedScript(async () => {
  // ...
  return "return value"
});

Copy link

netlify bot commented Apr 19, 2024

Deploy Preview for creative-fairy-df92c4 ready!

Name Link
🔨 Latest commit d91277f
🔍 Latest deploy log https://app.netlify.com/sites/creative-fairy-df92c4/deploys/663564ea3047cf00087191f1
😎 Deploy Preview https://deploy-preview-624--creative-fairy-df92c4.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Apr 19, 2024

Codecov Report

Attention: Patch coverage is 55.00000% with 27 lines in your changes are missing coverage. Please review.

Project coverage is 86.49%. Comparing base (21106ce) to head (d91277f).
Report is 1 commits behind head on main.

Files Patch % Lines
...irtual/content-script-isolated-world-entrypoint.ts 0.00% 9 Missing ⚠️
...rc/virtual/content-script-main-world-entrypoint.ts 0.00% 9 Missing ⚠️
...ages/wxt/src/virtual/unlisted-script-entrypoint.ts 0.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #624      +/-   ##
==========================================
- Coverage   86.66%   86.49%   -0.17%     
==========================================
  Files         112      112              
  Lines        9061     9111      +50     
  Branches      908      910       +2     
==========================================
+ Hits         7853     7881      +28     
- Misses       1194     1216      +22     
  Partials       14       14              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

package.json Outdated
"version": "0.17.12",
"version": "0.17.13-alpha1",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert before merging

@aklinker1 aklinker1 self-assigned this Apr 20, 2024
@aklinker1
Copy link
Collaborator Author

Waiting for validation from discord to make sure this works for the person who reported it...

https://discord.com/channels/1212416027611365476/1229813661821046794/1229813661821046794

@aklinker1
Copy link
Collaborator Author

aklinker1 commented May 3, 2024

Gonna go ahead and merge this, original user hasn't responded for a week or so, and there's already too many PRs in draft right now...

@aklinker1 aklinker1 marked this pull request as ready for review May 3, 2024 22:28
@aklinker1 aklinker1 merged commit 792e303 into main May 3, 2024
15 checks passed
@aklinker1 aklinker1 deleted the execute-return-value branch May 3, 2024 22:32
@aklinker1
Copy link
Collaborator Author

Released in v0.18.0

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

Successfully merging this pull request may close these issues.

Return values from unlisted scripts
1 participant