The extension has stopped working with the manifest of Google Chrome v2

I am developing a Google Chrome extension that works fine, but now has stopped working with version 2 of the manifest.

This gives me the following error:

Uncaught SyntaxError: Unexpected end of input 

popup.js:

 chrome.tabs.getSelected(null, function (aba) { link = aba.url; titulo = aba.title; document.getElementById('mensagem').value = link; }); function GrabIFrameURL(feedDescription) { var regex = new RegExp("iframe(?:.*?)src='(.*?)'", 'g'); var matches = regex.exec(feedDescription); var url = ''; if (matches.length == 2) { url = matches[1]; } var quebra = url.split("/"); return quebra[4]; } $(document).ready(function () { if (localStorage.nome == '' || localStorage.nome == null || localStorage.email == '' || localStorage.email == null) { jQuery('#formulario').hide(); jQuery('#erros').html('Configure seus dados <a href="options.html" target="_blank">aqui</a>'); } jQuery("#resposta").ajaxStart(function () { jQuery(this).html("<img src='img/loading.gif'> <b>SugestΓ£o sendo enviada, aguarde...</b>"); }); jQuery('#submit').click(function () { var nome = localStorage.nome; var email = localStorage.email; var mensagem = titulo + "\n\n<br><br>" + link; jQuery('#formulario').hide(); jQuery.post('http://blabloo.com.br/naosalvo/mail.php', { nome: nome, email: email, mensagem: mensagem }, function (data, ajaxStart) { jQuery('#resposta').html(data); console.log(data); }); return false; }); //Listagem de posts var bkg = chrome.extension.getBackgroundPage(); jQuery('#close').click(function () { window.close(); }); jQuery('#markeall').click(function () { bkg.lidoAll(); $('.naolido').attr('class', 'lido'); }); jQuery.each(bkg.getFeed(), function (id, item) { if (item.naolido == '1') lidoClass = 'naolido'; else lidoClass = 'lido'; var thumb = GrabIFrameURL(item.description); $('#feed').append('<li><a id="' + item.id + '" href="' + item.link + '" class="' + lidoClass + '"><img src="' + $.jYoutube(thumb, 'small') + '" class="' + lidoClass + '"/>' + item.title + '</a></li>'); }); $('.naolido').click(function (e) { e.preventDefault(); klicked = $(this).attr('id'); console.log(klicked); bkg.setLido(klicked); $(this).attr('class', 'lido'); openLink($(this).attr('href')); }); $('.lido').click(function (e) { openLink($(this).attr('href')); }); var openLink = function (link) { chrome.tabs.create({ 'url': link, 'selected': true }); window.close(); } }); 

I think the problem is in this part of popup.js:

 jQuery.each(bkg.getFeed(), function (id, item) { if (item.naolido == '1') lidoClass = 'naolido'; else lidoClass = 'lido'; var thumb = GrabIFrameURL(item.description); $('#feed').append('<li><a id="' + item.id + '" href="' + item.link + '" class="' + lidoClass + '"><img src="' + $.jYoutube(thumb, 'small') + '" class="' + lidoClass + '"/>' + item.title + '</a></li>'); }); 
+4
source share
1 answer

The problem is actually in background.js on lines 12 and 20, you first set localStorage.items to '' and then try to run JSON.parse() on it later, but this is not JSON data, so JSON.parse returns Unexpected end of input . And JSON.parse is not a function that you define, but a built-in browser function, so it displays as "line 1".

Try first defining it as an empty array, and then "push" it, as it is now.

+1
source

Source: https://habr.com/ru/post/1434976/


All Articles