dart-gde/chrome.dart

js.scoped not declared

MartinHo12 opened this issue · 17 comments

What steps will reproduce the problem?

  1. execute following code in chrome.dart serial example :
Serial.ports.then((result) {
logger.fine("getPorts = ${result}");
logger.fine("getPorts = ${result.runtimeType}");
result.forEach((port) {
  logger.fine("port = ${port} , ${port.runtimeType}");

  OptionElement optionElement = new OptionElement();
  optionElement.value = port;
  optionElement.text = port;
  selectElement.append(optionElement);
});

});
2.
3.

What is the expected output? What do you see instead?

Should be no error, but always "Breaking on exception: No top-level method 'js.scoped' declared."

What version of the product are you using? On what operating system?

Dart Editor version 1.0.0_r30798 (STABLE)
Dart SDK version 1.0.0.10_r30798

Please provide any additional information below.

I think js.scoped method has been removed from js package, I tried to add : import 'dart:js' as js;

however, still same failed result

Is there anyone knows how to bypass this issue ?

This package is not really being maintained anymore. Search for the
chrome_gen project on github for a better alternative.

Marc

Got it and thanks !

Hi,
Is there any example code for using ChromeSerial ? I am rookie in Dart and Java script ...
Martin

Hi,

ChromeSerial serial;

=> serial = null

var serial = new ChromeSerial();

=> ChromeSerial dose not have default constructor

what is the correct code to get a ChromeSerial instance ?

Martin

@MartinHo12 https://github.com/dart-gde/chrome_gen.dart/blob/master/lib/gen/serial.dart

We mimic the javascript api so no constructors are needed for the exposed API. If your passing arguments then those arguments might require a constructed object.

For serial you should just import and use serial

Would look something like:

import 'package:chrome_gen/chrome_app.dart' as chrome;

main() {
  chrome.serial.getPorts().then((List<String> ports) => print("Ports Available: $ports"));
}

Hi,

I tried following code :

import 'dart:html';
import 'dart:async';
import 'package:logging/logging.dart';
import 'package:chrome_gen/chrome_app.dart' as chrome;

List ports;
var result=chrome.serial.getPorts();
result.then((ports) => print('Available port : $ports'));

there is no compile warning or error, but when execution in dart editor :

Breaking on exception: Unsupported operation: 'chrome.serial' is not available

Can you help ? Thanks a lot.

It's likely that you need the serial permission in your manifest.json file:

http://developer.chrome.com/apps/serial.html

Hi,

I checked manifest.json, there is serial permission added.

I tried to execute the code directly in dart editor 'run'  command and failed. I also build the code into Java script and lunch through Chrome browser, still same problem.

 I guess this problem is due to some very basic setting of execution environment, I tried chrome_gen demo app,  every class instance used in demo app is not available ....      

If you're using the Editor, you need to right-click on the manifest.json file and choose 'Run as chrome app'. If the editor instead launches the html file it'll run as a normal web application and none of the chrome apis will be available. It seems like that's what is happening here -

Hi Devon,

 Yes, 'Run as chrome app' is the solution. Thanks a lot.

 I tried further to write a string through com port using :

         chrome.serial.write(connId, data);

   data is ArrayBuffer type, Do you know how to convert a string to ArrayBuffer in Dart ?

I think you'll have to do something like:

new chrome.ArrayBuffer.fromString(foo)

I think you've run into issues that a lot of new users would commonly hit. It would be worth spending the time to convert the chrome_gen wiki into a FAQ of common issues (https://github.com/dart-gde/chrome_gen.dart/wiki). Or perhaps annotating the main readme.md w/ a small FAQ?

Hi,

I just put above issues into FAQ. The editor seems ignore linefeed/return, the layout looks weird but I don't know how to fixed it.
I already complete a program that can open, read and write through serial port based on chrome_gen. Thanks a lot for your help. Maybe this program can be used as part of  examples package for chrome_gen in the future.

Martin

@MartinHo12 in the future I do hope to port the samples to chrome_gen.dart. Eventually chrome_gen.dart will replace chrome.dart.

@MartinHo12 I fixed up the formatting. I think question 1, could be written explaining that we are following the existing chrome apps/extensions javascript convention for a singleton design pattern on each api namespace.

Great! I added a link to the FAQ from the main readmd.md.