简体   繁体   English

如何在Chrome打包应用中的background.js中包含Chrome Javascript API?

[英]How do I include a Chrome Javascript API in the background.js in a Chrome Packaged App?

I've just recently began working on my own packaged app for Google Chrome. 我最近才开始为Google Chrome开发自己的打包应用程序。 Since it's mostly just standard HTML, CSS, and Javascript, I have found it fairly easy to put together. 由于大多数只是标准HTML,CSS和Javascript,因此我发现将其组合起来相当容易。 However, I've been having difficulty using the API features added by Google and can find very little information on it. 但是,我一直在使用Google添加的API功能时遇到困难,并且很难找到有关它的信息。

I've tried to add in the API to the background.js 's code in several different places, but each time, the app fails to launch (nothing happens when I open it). 我试图在几个不同的地方将API添加到background.js的代码中,但是每次应用程序启动失败(打开应用程序都不会发生任何事情)。

Here's what I found on developer.chrome.com that I've been using as a reference: 这是我在developer.chrome.com上找到的用作参考的内容:

chrome.app.window.create(string url, object options, function callback)

And here's the background.js page that I'm using with frame('none'), added in: 这是我正在使用frame('none')的background.js页面添加在其中:

chrome.app.runtime.onLaunched.addListener(function() {
 chrome.app.window.create('window.html', frame('none'), {
    'bounds': {
      'width': 700,
      'height': 600,
      }
 });
});

I know this is probably a stupid question with an obvious answer, but any help is greatly appreciated. 我知道这可能是一个愚蠢的问题,答案很明显,但是任何帮助都将不胜感激。

As kzahel mentions the syntax for frame is wrong. 正如kzahel所述,frame的语法是错误的。 It also should be merged into the next argument you've provided for bounds, which is also part of the options. 还应将其合并到为边界提供的下一个参数中,这也是选项的一部分。

What you want is something more like: 您想要的更像是:

chrome.app.runtime.onLaunched.addListener(function() {
  chrome.app.window.create('window.html', {
    frame: 'none',
    bounds: {
      'width': 700,
      'height': 600
    }
  });
});

You have a typo. 你有错字 instead of "frame('none')", it should read {frame:'none'}. 而不是“ frame('none')”,它应显示为{frame:'none'}。 It's not launching because you're trying to call frame as a function. 它没有启动,因为您正在尝试将frame作为函数调用。 chrome.app.window.create wants an object as the second argument. chrome.app.window.create想要一个对象作为第二个参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Chrome打包应用程序 - 从background.js传递到另一个脚本页面的消息 - Chrome Packaged App - Message passing from background.js to another script page 如何动态更改background.js以在chrome中反映用户的设置? - How do I dynamically change the background.js to reflect a user's setting in chrome? 如何在background.js中为Chrome扩展程序使用自定义功能? - How do I use a custom function in background.js for a Chrome Extension? 哪个 Chrome 扩展程序 API 可以让计时器在 background.js 中运行? - Which Chrome Extension API to keep timer running in background.js? 如何通过javascript启动Chrome打包应用? - How can I launch a Chrome Packaged App through javascript? 如何使用版本 3 在 chrome 扩展中的 background.js 中导入 javascript 个文件 - How to import javascript files in background.js in chrome extension using version 3 如何在Google Chrome扩展程序中将信息从Background.js传递到autofill.js? - How can I pass information from Background.js to autofill.js in my Google Chrome extension? 如何在 Chrome 扩展程序的 background.js 中调试事件侦听器 - How to debug event listener in background.js in Chrome extension 在 background.js 中的 Chrome 扩展中的 setInterval - setInterval in Chrome extension in background.js chrome 扩展中 background.js 的用途是什么? - What is the purpose of background.js on a chrome extension?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM