Why do I get "Uncaught TypeError: navigator.bluetooth.getAvailability is not a function" - web-bluetooth

The following code, executing on a chromebook with Chrome version 59.0.3071.134 (Official Build) (64-bit) is generating "Uncaught TypeError: navigator.bluetooth.getAvailability is not a function". Any idea why?
bluetoothle.checkBluetoothAvailable = function() {
console.log("checkBluetoothAvailable");
navigator.bluetooth.getAvailability().then(isAvailable => {
document.getElementById('btn_discover').hidden = !isAvailable;
if (!isAvailable) {
document.getElementById('message').innerHTML = 'Bluetooth is not available';
}
});
navigator.bluetooth.addEventListener('availabilitychanged', e => {
document.getElementById('btn_discover').hidden = !e.value;
if (!e.value) {
document.getElementById('message').innerHTML = 'Bluetooth is not available';
} else {
document.getElementById('message').innerHTML = 'Bluetooth is available';
}
});
}

getAvailability is not implemented. It is specified, so it makes sense to try it and expect it to work.
https://github.com/WebBluetoothCG/web-bluetooth/blob/gh-pages/implementation-status.md lists what has been implemented in more detail.
And, in the specification you will find the background of some sections such as getAvailability include "This section is not stable." and background text "Unstable".

Related

Using this.skip with cypress-json-failed results in: TypeError: Cannot read properties of undefined (reading 'message')

I am attempting to use a global beforeeach() algorithm defined in support/e2e to filter tests. This code works.
beforeEach(function () {
var testSuite = new Array();
testSuite = (Cypress.env('suites'));
if (!testSuite) {
return;
}
const testName = Cypress.mocha.getRunner().test.fullTitle().toLowerCase();
let matches = testSuite.some((value) => {
return (testName.includes(value))
});
if (!matches) {
this.skip();
}
return;
})
However, when using in conjunction with cypress-failed-log, tests that are skipped because of the prior algorithm are failing with this error:
TypeError: Cannot read properties of undefined (reading 'message')
Because this error occurred during a `after each` hook we are skipping all of the remaining tests.
at Context.onFailed (webpack:///./node_modules/cypress-failed-log/src/index.js:136:0)
This is what my plug in looks like. It works independent of the sorting algorithm and fails with the same message even if I only leave just the failed:required line and remove the code that uses the message object.
on('task', {
failed: require('cypress-failed-log/src/failed')()
,
log(message) {
console.log(message)
return null
},
table(message) {
console.table(message)
return null
}
})

Parse iOS Universal Links with Nativescript Angular?

Following the apple documentation and Branch's documentation here, I have set up a working universal link in my Nativescript Angular (iOS) app. But, how do I parse the link when the app opens?
For example, when someone opens the app from the link, I want to have my app read the link so it can go to the correct page of the app.
There is some helpful code in this answer, but I keep getting errors with it. This could be bc the code is written in vanilla JS and I am not translating it into Angular correctly. The use of "_extends" and "routeUrL" both cause errors for me.
And the Nativescript url-handler plugin does not seem to work without further code.
So, after setting up the universal link, and installing the nativescript url-handler plugin, I have entered the following in app.module.ts:
const Application = require("tns-core-modules/application");
import { handleOpenURL, AppURL } from 'nativescript-urlhandler';
declare var NSUserActivityTypeBrowsingWeb
if (Application.ios) {
const MyDelegate = (function (_super) {
_extends(MyDelegate, _super);
function MyDelegate() {
_super.apply(this, arguments);
}
MyDelegate.prototype.applicationContinueUserActivityRestorationHandler = function (application, userActivity) {
if (userActivity.activityType === NSUserActivityTypeBrowsingWeb) {
this.routeUrl(userActivity.webpageURL);
}
return true;
};
MyDelegate.ObjCProtocols = [UIApplicationDelegate];
return MyDelegate;
})(UIResponder);
Application.ios.delegate = MyDelegate;
}
...
export class AppModule {
ngOnInit(){
handleOpenURL((appURL: AppURL) => {
console.log('Got the following appURL = ' + appURL);
});
}
}
The trouble seems to be mostly with "_extends" and "_super.apply". For example, I get this error:
'NativeScript encountered a fatal error: TypeError: undefined is not an object (evaluating '_extends')
EDIT: Note that the nativescript-urlhandler plugin is no longer being updated. Does anyone know how to parse universal links with Nativescript?
I have figured out a method to get this working:
The general idea is to use the iOS App Delegate method: applicationContinueUserActivityRestorationHandler.
The syntax in the Nativescript documentation on app delegates did not work for me. You can view that documentation here.
This appears to work:
--once you have a universal link set up, following documentation like here, and now you want your app to read ("handle") the details of the link that was tapped to open the app:
EDIT: This code sample puts everything in one spot in app.module.ts. However, most of the time its better to move things out of app.module and into separate services. There is sample code for doing that in the discussion here. So the below has working code, but keep in mind it is better to put this code in a separate service.
app.module.ts
declare var UIResponder, UIApplicationDelegate
if (app.ios) {
app.ios.delegate = UIResponder.extend({
applicationContinueUserActivityRestorationHandler: function(application, userActivity) {
if (userActivity.activityType === NSUserActivityTypeBrowsingWeb) {
let tappedUniversalLink = userActivity.webpageURL
console.log('the universal link url was = ' + tappedUniversalLink)
}
return true;
}
},
{
name: "CustomAppDelegate",
protocols: [UIApplicationDelegate]
});
}
NOTE: to get the NSUserActivity/Application Delegate stuff to work with typescript, I also needed to download the tns-platforms-declarations plugin, and configure the app. So:
$ npm i tns-platforms-declarations
and
references.d.ts
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
The above code works for me to be able to read the details of the tapped universal link when the link opens the app.
From there, you can determine what you want to do with that information. For example, if you want to navigate to a specific page of your app depending on the details of the universal link, then I have found this to work:
app.module.ts
import { ios, resumeEvent, on as applicationOn, run as applicationRun, ApplicationEventData } from "tns-core-modules/application";
import { Router } from "#angular/router";
let univeralLinkUrl = ''
let hasLinkBeenTapped = false
if (app.ios) {
//code from above, to get value of the universal link
applicationContinueUserActivityRestorationHandler: function(application, userActivity) {
if (userActivity.activityType === NSUserActivityTypeBrowsingWeb) {
hasLinkBeenTapped = true
universalLinkUrl = userActivity.webpageURL
}
return true;
},
{
name: "CustomAppDelegate",
protocols: [UIApplicationDelegate]
});
}
#ngModule({...})
export class AppModule {
constructor(private router: Router) {
applicationOn(resumeEvent, (args) => {
if (hasLinkBeenTapped === true){
hasLinkBeenTapped = false //set back to false bc if you don't app will save setting of true, and always assume from here out that the universal link has been tapped whenever the app opens
let pageToOpen = //parse universalLinkUrl to get the details of the page you want to go to
this.router.navigate(["pageToOpen"])
} else {
universalLinkUrl = '' //set back to blank
console.log('app is resuming, but universal Link has not been tapped')
}
})
}
}
You can use the nativescript-plugin-universal-links plugin to do just that.
It has support for dealing with an existing app delegate so if you do have another plugin that implements an app delegate, both of them will work.
Here's the usage example from the docs:
import { Component, OnInit } from "#angular/core";
import { registerUniversalLinkCallback } from "nativescript-plugin-universal-links";
#Component({
selector: "my-app",
template: "<page-router-outlet></page-router-outlet>"
})
export class AppComponent {
constructor() {}
ngOnInit() {
registerUniversalLinkCallback(ul => {
// use the router to navigate to the screen
});
}
}
And the callback will receive a ul (universal link) param that looks like this
{
"href": "https://www.example.com/blog?title=welcome",
"origin": "https://www.example.com",
"pathname": "/blog",
"query": {
"title": "welcome"
}
}
Disclaimer: I'm the author of the plugin.

Redirect with ci flash message Connot modify header information error occue

I'm trying to redirect after executing some code with flash message then apache hang and sent error
Connot modify header information - headers already sent
public function convert_to_invoice($id)
{
if (!has_permission('invoices', '', 'create')) {
access_denied('invoices');
}
if (!$id) {
die('No estimate found');
}
$draft_invoice = false;
if ($this->input->get('save_as_draft')) {
$draft_invoice = true;
}
$invoiceid = $this->estimates_model->convert_to_invoice($id, false, $draft_invoice);
if ($invoiceid) {
$this->session->set_flashdata('message-success','estimate_convert_to_invoice_successfully');
redirect('invoices/list_invoices/' . $invoiceid);
} else {
if ($this->session->has_userdata('estimate_pipeline') && $this->session->userdata('estimate_pipeline') == 'true') {
$this->session->set_flashdata('estimateid', $id);
}
if ($this->set_estimate_pipeline_autoload($id)) {
redirect($_SERVER['HTTP_REFERER']);
} else {
redirect(admin_url('estimates/list_estimates/' . $id));
}
}
}
As redirect uses headers to perform its task nothing can be outputted before it is called. I don't see anything that would cause output except:
if (!has_permission('invoices', '', 'create')) {
access_denied('invoices'); // exits?
}
if (!$id) {
die('No estimate found');
}
However both seem to exit so the redirect stage shouldn't be reached.
I would suggest removing the redirects temporarily, running the script, and seeing what is outputting. You can then remove/silence those offending pieces of code and re-institute the redirects. It might be as simple as an error outputting.

PerformanceObserver throwing error in Firefox, working in Chrome

I am implementing PerformanceObserver to track 'first-paint' & 'first-contentful-paint'.
const observer = new PerformanceObserver((list) => {
for (const entry of list.getEntries()) {
if (typeof(Storage) !== 'undefined') {
if (entry.name === 'first-paint') {
localStorage.setItem(rumMetrics.RUM_METRICS_FIRST_PAINT, entry.startTime);
}
else if (entry.name === 'first-contentful-paint') {
localStorage.setItem(rumMetrics.RUM_METRICS_FIRST_CONTENTFUL_PAINT, entry.startTime);
}
}
else {
console.log('local storage is not supported here. RUM metrics won\'t be recorded.');
}
}
});
observer.observe({ entryTypes: ['paint'] });
This works perfectly in Chrome but throws an error in Firefox.
TypeError: The expression cannot be converted to return the specified type. (line: observer.observe({ entryTypes: ['paint'] });)
Update-1: 20th Apr 2018
Mozilla has confirmed the bug and it is affecting FF61 Nightly as well
Original Answer
Confirmed that this is a bug even in the developer version.
Below is the bug for the same
https://bugzilla.mozilla.org/show_bug.cgi?id=1454581

cannot find the datastore during the compiling in Angular2

When I try to run my page in Wakanda studio 1.1.3, I am getting an error during the compiling when converting the TS to JS. It shows me an error stating "cannot find the datastore"; which is present in my wakanda database. Is anyone else getting the same error?
here is the code:
this.wakanda.catalog.then(ds=>{
ds.TestDatabase.testmethod().then(op=>{
console.log(op);
});
});
my wakanda.service.ts is of the following
import {WakandaClient} from 'wakanda-client/browser/no-promise';
export class Wakanda {
private _client: WakandaClient;
private _catalog;
constructor() {
//this._client = new WakandaClient({ host: 'http://127.0.0.1:8081' });
this._client = new WakandaClient({});
this._catalog = null;
}
get catalog() {
if (!this._catalog) {
return this._client.getCatalog().then(c => {
this._catalog = c;
return c;
});
}
return Promise.resolve(this._catalog);
}
get directory() {
return this._client.directory;
}
get wakandaClientVersion() {
return this._client.version();
}
}
where TestDatavase is a table in my datastore and has a method called testmethod.
[default]
/Users/adithyavinayak/Documents/Wakanda/solutions/TestDatabase/TestDatabase/web/src/app/home/home.component.ts:21:8
Property 'TestDatabase' does not exist on type 'Catalog'. [default]
Checking finished with 4 errors
This one happens even if i make a call to any datastore during compile time.
The solution for this problem is by using the return type of the catalog to any
this.wakanda.catalog.then((ds:any)=>{
ds.TestDatabase.testmethod().then(op=>{
console.log(op);
});
});
This one works without any problem during the time of compilation.

Resources