I’m building a Chrome extension that should automatically apply a “priority” label to selected emails when users click a custom button. I’m using InboxSDK for the button interface and Gmail API for the actual labeling, but I keep getting a syntax error.
The error shows up as:
Uncaught SyntaxError: Unexpected token <
This happens in my main script file. Here’s my setup:
// manifest.json
{
"name": "Email Labeler",
"description": "Auto-label emails",
"version": "1.0",
"manifest_version": 2,
"background": {
"page": "/background/main.html"
},
"content_scripts": [{
"matches": ["https://mail.google.com/*"],
"js": ["/libs/inboxsdk.js", "/scripts/labeler.js"],
"run_at": "document_end"
}],
"permissions": ["identity", "https://www.googleapis.com/*"],
"oauth2": {
"client_id": "your-client-id.apps.googleusercontent.com",
"scopes": ["https://www.googleapis.com/auth/gmail.modify"]
}
}
// main.html
<!DOCTYPE html>
<html>
<head>
<title>Email Labeler</title>
<script src="authentication.js"></script>
</head>
<body>
<div id="auth-section">
<button id="auth-btn" onclick="startAuth()">Connect Gmail</button>
</div>
</body>
</html>
// authentication.js
var APP_ID = 'your-client-id.apps.googleusercontent.com';
var PERMISSIONS = ['https://www.googleapis.com/auth/gmail.modify'];
function startAuth() {
gapi.auth.authorize({
'client_id': APP_ID,
'scope': PERMISSIONS,
'immediate': false
}, authCallback);
}
function authCallback(result) {
if (result && !result.error) {
loadGmailClient();
}
}
function loadGmailClient() {
gapi.client.load('gmail', 'v1', applyLabels);
}
// labeler.js
function applyLabels() {
var apiRequest = gapi.client.gmail.users.labels.list({
'userId': 'me'
});
apiRequest.execute(function(response) {
function setupToolbar(inboxSDK) {
inboxSDK.Toolbars.registerToolbarButtonForList({
title: 'Priority Label',
iconUrl: chrome.extension.getURL('/icons/label.png'),
onClick: function() {
var selectedThreads = inboxSDK.Lists.getSelectedThreadRowViews();
selectedThreads.forEach(function(thread) {
thread.addLabel('Priority');
});
alert('Emails labeled as Priority');
}
});
}
InboxSDK.load('1', 'sdk_key_here').then(setupToolbar);
});
}
What could be causing this syntax error? Any help would be appreciated.