You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Chrome扩展Storage API语法报错:第二行出现'Uncaught SyntaxError: Unexpected token )'?

Let's break down both of the errors you're hitting with the Chrome Extension Storage API, step by step:

1. Uncaught SyntaxError: Unexpected token )

This is a basic JavaScript syntax error, plain and simple. The root cause is that your code has a mismatched or misplaced parenthesis in the line where you're calling the Storage API's get method.

Common scenarios that trigger this:

  • You accidentally added an extra closing parenthesis when defining the get call, like this:
    chrome.storage.local.get('myStoredKey', ); // Extra ) here breaks syntax
    
  • You messed up the bracket/parenthesis pairing for your callback function, such as forgetting an opening brace or closing parenthesis:
    chrome.storage.local.get('myStoredKey', function(result) { console.log(result) ) // Missing closing }
    

The JavaScript parser can't make sense of the invalid syntax, so it throws this error immediately. Double-check the second line of your code to fix all parenthesis/brace mismatches.

2. extensions::StorageArea:35 Uncaught Error: Invocation of form get(string) doesn't match definition...

This error comes from not following the Chrome Storage API's required method signature.

Looking at the error message's definition: get(optional string or array or object keys, function callback), the second parameter (the callback function) is required when using the traditional callback-based version of the API. You can't just pass a key and omit the callback—this violates the API's expected input structure.

Here's how to fix it:

Option 1: Use the required callback (works for all Chrome versions)

chrome.storage.local.get('myStoredKey', function(storageResult) {
  // Do something with the result, like log it or update your UI
  console.log('Fetched value:', storageResult.myStoredKey);
});

Option 2: Use Promise-based syntax (Chrome 88+)

If you're targeting Chrome 88 or newer, you can skip the callback entirely by using the Promise version of the API (no more mandatory callback):

async function fetchStoredValue() {
  const storageResult = await chrome.storage.local.get('myStoredKey');
  console.log('Fetched value:', storageResult.myStoredKey);
}
fetchStoredValue();

Just make sure your extension's manifest or target Chrome version supports this syntax.


内容的提问来源于stack exchange,提问作者difoxy2

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:23:04