I’m in the process of developing a Chrome extension that aims to label selected Gmail emails. The extension is supposed to utilize InboxSDK for creating a button and apply labels using the Gmail API based on user interaction. Unfortunately, I’m encountering an error when I click the button intended for tagging.
The error message I’m getting is:
Uncaught SyntaxError: Unexpected token <
Here is how I’ve structured my code:
manifest.json:
{
"name": "Email Tagger",
"description": "Tags selected emails",
"version": "0.2",
"manifest_version": 2,
"background": {
"page": "/background/script.html"
},
"content_scripts": [{
"matches": ["https://mail.google.com/*", "https://inbox.google.com/*"],
"js": ["/libs/inboxsdk.js", "/libs/alertify/alertify.min.js", "/scripts/tagger.js"],
"run_at": "document_end"
}],
"permissions": ["identity", "<all_urls>", "tabs"],
"oauth2": {
"client_id": "sample-client-id.apps.googleusercontent.com",
"scopes": ["https://mail.google.com/", "https://www.googleapis.com/auth/gmail.modify"]
}
}
script.html:
<!DOCTYPE html>
<html>
<head>
<title>Email Tagger</title>
<script src="auth.js"></script>
<script src="/libs/inboxsdk.js"></script>
<script src="/scripts/tagger.js"></script>
</head>
<body>
<div id="auth-container" style="display: none">
<span>Authorize access to Gmail API</span>
<button id="auth-btn" onclick="handleAuthentication(event)">Authorize</button>
</div>
</body>
</html>
auth.js:
var CLIENT_ID = 'sample-client-id.apps.googleusercontent.com';
var SCOPES = ['https://mail.google.com/', 'https://www.googleapis.com/auth/gmail.modify'];
function checkAuthentication() {
gapi.auth.authorize({
'client_id': CLIENT_ID,
'scope': SCOPES,
'immediate': true
}, handleAuthResult);
}
function handleAuthResult(authResult) {
var authDiv = document.getElementById('auth-container');
if (authResult && !authResult.error) {
authDiv.style.display = 'none';
initiateGmailApi();
} else {
authDiv.style.display = 'block';
}
}
function handleAuthentication(event) {
gapi.auth.authorize({
'client_id': CLIENT_ID,
'scope': SCOPES,
'immediate': false
}, handleAuthResult);
return false;
}
function initiateGmailApi() {
gapi.client.load('gmail', 'v1', applyLabel);
}
tagger.js:
function applyLabel() {
var request = gapi.client.gmail.users.labels.update({
'userId': 'me'
});
request.execute(function(response) {
function addToolbar(inboxSDK) {
inboxSDK.Toolbars.registerToolbarButtonForList({
title: 'General',
iconUrl: chrome.extension.getURL('/icons/tag.png'),
onClick: function() {
var label = GmailApp.getUserLabelByName("General");
var threads = label.getThreads();
for (var i = 0; i < threads.length; i++) {
threads[i].addLabel(label);
}
alertify.success('Threads tagged as General');
}
});
}
InboxSDK.load('1', 'sdk_tagger_xyz').then(addToolbar);
});
}
I would greatly appreciate any help in resolving this syntax issue.